Jump to content


Photo

Smarty/Validation/Session problem


  • Please log in to reply
3 replies to this topic

#1 simonsays

simonsays
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 26 June 2006 - 07:39 PM

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
<?
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');

?>

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:
<?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);
?>

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!

#2 timmah22

timmah22
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 June 2006 - 11:53 PM

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) View Post[/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
<?
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');

?>

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:
<?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);
?>

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]

timmah uses [a href="http://wakeupcalls.net" target="_blank"]wake up calls dot net[/a]

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 27 June 2006 - 01:42 AM

In image.php add session_start() as the first line.
Legend has it that reading the manual never killed anyone.
My site

#4 simonsays

simonsays
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 27 June 2006 - 08:47 AM

timmah22, that page was generated using Smarty Engine.

AndyB, thanks a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users