Jump to content

Smarty/Validation/Session problem


simonsays

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.