Reply to Re: [SMARTY] How to use Smarty and Sessions

Your name:

Reply:


Posted by Robert Amos on 04/10/05 11:41

First off, the first error suggests you look in your file "users.php"
and that you're specifying an invalid session name on line 2.

The second error suggests that the web server is unable to write to
your session savedata folder (C:\php5\savedata). Double check
permissions on that directory, or else change it to somewhere under
the windows temp dir.

-bok

On Apr 10, 2005 5:58 PM, Reynier Perez Mira <rperezm@estudiantes.uci.cu> wrote:
> Well. I create a web in wich users can register. I use GD and images to create the call Security Code. Take a look to the code I programed to this functionallity:
>
> File: securitycode.php
>
> <?PHP
> error_reporting(85);
> session_start();
> // Config Vars
> $_SESSION['max_digits'] = 7;
> $bg_image = "code_bg.jpg";
> $font = 100;
> $code_color = "FF7700";
> $noautomationcode = $_SESSION["noautomationcode"];
> $img = imagecreatefromjpeg($bg_image);
> $img_size = getimagesize($bg_image );
> $fw = imagefontwidth($font);
> $fh = imagefontheight($font);
> $x = ($img_size[0] - strlen($noautomationcode) * $fw )/2;
> $y = ($img_size[1] - $fh) / 2;
> $color = imagecolorallocate($img,hexdec(substr($config_code_color,1,2)),hexdec(substr($config_code_color,3,2)),hexdec(substr($config_code_color,5,2)));
> imagestring ( $img, $font, $x, $y, $noautomationcode, $color);
> header("Content-Type: image/jpeg");
> imagejpeg($img);
> ?>
>
> Now in the PHP file I have this code to see the picture in a tpl file:
>
> File: register.php
>
> <?php
> session_start();
> ob_start();
> require("class/smarty/Smarty.class.php");
> include_once("language/lang-spanish.php");
> include_once('class/DB.php');
> $sid = session_id();
> $noautomationcode = "";
> for($i=0; $i<$_SESSION['max_digits'];$i++)
> $noautomationcode = $noautomationcode.rand(0,9);
> $_SESSION["noautomationcode"] = $noautomationcode;
> $template = new Smarty();
> $dsn = 'mysql://root:reyniermysql@localhost/jovenclub';
> $database = DB::connect($dsn);
> if (DB::isError($database)) {
> die($database->getMessage());
> }
> /* Class smarty config */
> $template->template_dir = "themes/";
> $template->compile_dir = "themes/themes_c/";
> $template->config_dir = "themes/config/";
> $template->compile_check = true;
> /* Check if user is loged in or not */
> if(isset($_SESSION['jc_uname']) && ($_SESSION['jc_uname']!=null || $_SESSION['jc_uname']!="")){
> $uname = base64_decode($_SESSION['uname']);
> $template->assign("WELCOME",_WELCOME);
> $template->assign("USERNAME", $uname);
> }else{
> $template->assign("CONECTORREGISTER",_CONECTORREGISTER);
> }
> $result = $database->query('SELECT * FROM frases_celebres ORDER BY RAND()');
> while(list($frase,$autor) = $result->fetchRow ()){
> $template->assign("FRASE_CELEBRE",$frase." - ".$autor);
> }
> /* Assign values to constants or dinamic vars */
> $template->assign("COPYRIGHT",COPYRIGHT);
> $template->assign('yesterday', strtotime('-1 day'));
> $template->assign("UNAME",_UNAME);
> $template->assign("UCORREO",_UCORREO);
> $template->assign("UNICK",_UNICK);
> $template->assign("UPASS1",_UPASS1);
> $template->assign("UPASS2",_UPASS2);
> $template->assign("UPASSB",_UPASSB);
> $template->assign("SECURITYCODE","<img src='securitycode.php?sid=$sid'>"); // hear I assign to a TPL var his value
> $template->assign("OTROSDATOS",_OTROSDATOS);
> $template->assign("UICQ",_UICQ);
> $template->assign("UYIM",_UYIM);
> $template->assign("UMSN",_UMSN);
> $template->assign("UAOL",_UAOL);
> $template->assign("USWWW",_UWWW);
> $template->assign("UINTERESES",_UINTERESES);
> $template->assign("UOCUPACION",_UOCUPACION);
> $template->assign("UFIRMA",_UFIRMA);
> $template->assign("UPCORREO",_UPCORREO);
> $template->assign("UNCORREO",_UNCORREO);
> $template->assign("UAVATAR",_UAVATAR);
> $template->assign("UREGISTER",_UREGISTER);
> $template->assign("OBLIGATORIEDDATA",_OBLIGATORIEDDATA);
> $template->assign("U_NEW_REGISTER",_U_NEW_REGISTER);
> $template->display("header.tpl");
> $template->display("register.tpl");
> $template->display("footer.tpl");
> ob_end_flush();
> ?>
>
> All god, but surprise when I run the file into a web browser this error it's show me:
>
> Error:
>
> This at top:
>
> Warning: session_start() [function.session-start <http://localhost/jclub/function.session-start> ]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in D:\WWW\jclub\users.php on line 2
> Warning: session_start() [function.session-start <http://localhost/jclub/function.session-start> ]: Cannot send session cookie - headers already sent by (output started at D:\WWW\jclub\users.php:2) in D:\WWW\jclub\users.php on line 2
> Warning: session_start() [function.session-start <http://localhost/jclub/function.session-start> ]: Cannot send session cache limiter - headers already sent (output started at D:\WWW\jclub\users.php:2) in D:\WWW\jclub\users..php on line 2
>
> This at bottom:
>
> Warning: Unknown: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in Unknown on line 0
> Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\PHP5\sessiondata) in Unknown on line 0
> ***********************************************************************************************************************************
>
> And picture are not displayed only I see the tipically cross in red color..
>
> How can I solve this? It's possible ?
>
> Regards
>
> Reynier Pérez Mira
>
> 3ero. Ing. Informática
>
> Entre más inteligente me siento, más me doy cuenta de lo ignorante que soy.
>
>


--
Xnyo - http://xnyo.odynia.org/

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация