simonsays Posted June 26, 2006 Share Posted June 26, 2006 OK, I just started to rewrite my project using Smarty and I am new to this engine. I have come across a following problem: Here is a php file[code]<?require_once('Smarty.class.php');$smarty = new Smarty();$smarty->assign('self', $_SERVER['PHP_SELF']);$smarty -> assign('uid', $_SESSION['uid']);$smarty -> assign('pwd', $_SESSION['pwd']);if (isset($_POST['proceed']) && $_POST['proceed']=='yes'){$smarty -> assign('proceed', $_POST['proceed']);}$i=2001;while($i>=1920){$years[]=$i;$i--;}$smarty->assign('years', $years);session_start();$random = substr(md5(time()),0,6);$_SESSION['random']=$random;echo "Session is ". $_SESSION['random'];$smarty->display('reg.tpl');?>[/code]it does some minor routine, but the thing that interests me the most is the spot where it creates session. Echo that I use for control displays session contents perfectly.That session ($_SESSION['random']) is used later in the image.php script:[code]<?php$text = $_SESSION['random'];header("Content-type: image/png");$im = @imagecreate(65, 27) or die("Cannot Initialize new GD image stream");$background_color = imagecolorallocate($im, 255, 153, 0);$text_color = imagecolorallocate($im, 255, 255, 255);imagestring($im, 5, 5, 5, $text, $text_color);imagepng($im);imagedestroy($im);?> [/code]and there is a spot in .tpl file responsible for displaying it (<img src='image.php'>)The problem is that the image is blank (no string in it) and when I click 'submit' the registration validation script also gives error that session is empty.What's wrong? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/12955-smartyvalidationsession-problem/ Share on other sites More sharing options...
timmah22 Posted June 26, 2006 Share Posted June 26, 2006 Is any html being submitted before the session_start();? is the <?php at the top of the page?[!--quoteo(post=388183:date=Jun 26 2006, 02:39 PM:name=simonsays)--][div class=\'quotetop\']QUOTE(simonsays @ Jun 26 2006, 02:39 PM) [snapback]388183[/snapback][/div][div class=\'quotemain\'][!--quotec--]OK, I just started to rewrite my project using Smarty and I am new to this engine. I have come across a following problem: Here is a php file[code]<?require_once('Smarty.class.php');$smarty = new Smarty();$smarty->assign('self', $_SERVER['PHP_SELF']);$smarty -> assign('uid', $_SESSION['uid']);$smarty -> assign('pwd', $_SESSION['pwd']);if (isset($_POST['proceed']) && $_POST['proceed']=='yes'){$smarty -> assign('proceed', $_POST['proceed']);}$i=2001;while($i>=1920){$years[]=$i;$i--;}$smarty->assign('years', $years);session_start();$random = substr(md5(time()),0,6);$_SESSION['random']=$random;echo "Session is ". $_SESSION['random'];$smarty->display('reg.tpl');?>[/code]it does some minor routine, but the thing that interests me the most is the spot where it creates session. Echo that I use for control displays session contents perfectly.That session ($_SESSION['random']) is used later in the image.php script:[code]<?php$text = $_SESSION['random'];header("Content-type: image/png");$im = @imagecreate(65, 27) or die("Cannot Initialize new GD image stream");$background_color = imagecolorallocate($im, 255, 153, 0);$text_color = imagecolorallocate($im, 255, 255, 255);imagestring($im, 5, 5, 5, $text, $text_color);imagepng($im);imagedestroy($im);?> [/code]and there is a spot in .tpl file responsible for displaying it (<img src='image.php'>)The problem is that the image is blank (no string in it) and when I click 'submit' the registration validation script also gives error that session is empty.What's wrong? Thanks in advance![/quote] Link to comment https://forums.phpfreaks.com/topic/12955-smartyvalidationsession-problem/#findComment-49869 Share on other sites More sharing options...
AndyB Posted June 27, 2006 Share Posted June 27, 2006 In image.php add session_start() as the first line. Link to comment https://forums.phpfreaks.com/topic/12955-smartyvalidationsession-problem/#findComment-49906 Share on other sites More sharing options...
simonsays Posted June 27, 2006 Author Share Posted June 27, 2006 [b]timmah22[/b], that page was generated using Smarty Engine.[b]AndyB[/b], thanks a lot! Link to comment https://forums.phpfreaks.com/topic/12955-smartyvalidationsession-problem/#findComment-49994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.