Jump to content

Archived

This topic is now archived and is closed to further replies.

simonsays

Smarty/Validation/Session problem

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
In image.php add session_start() as the first line.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.