lwfuk
asked on
Oscommerce- Why do custom session vars get destroyed.
Hi
I'm developing an app using osc as the base. The problem is that my new session variables seem to get destroyed. I thought about using the tep_session functions but I can't work out how to assign and retrive a value.
Does anybody know why the session vars get destroyed and if not how you use the basic tep_session functions.
Kind Regards,
Adrian Smith
I'm developing an app using osc as the base. The problem is that my new session variables seem to get destroyed. I thought about using the tep_session functions but I can't work out how to assign and retrive a value.
Does anybody know why the session vars get destroyed and if not how you use the basic tep_session functions.
Kind Regards,
Adrian Smith
ASKER
Hi Ray
This works.
This works.
<?php
#Page1
require('includes/application_top.php');
if (!tep_session_is_registered('fig')) tep_session_register('fig');
$fig = "Charlotte";
?>
<?php
#Page2
require('includes/application_top.php');
echo $fig;
?>
ASKER
Actually ignore the above. I'll put together a better demo.
ASKER
This Works.
<?php
//test.php
//Include the standard head
require('includes/application_top.php');
//Define the session var
if (!tep_session_is_registered('captcha')){
tep_session_register('captcha');
$captcha = rand()%9 . rand()%9 . rand()%9 . rand()%9 . rand()%9;
}
//Print an image
<?php echo '<img src="captcha.php" width="50" height="11"/>' ?>
?>
<?php
//captcha.php
//Include the standard head
require('includes/application_top.php');
//Create an image
$im = imagecreatetruecolor(50, 11);
$bgColor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$txt = imagecolorallocate($im, 0x00, 0x76, 0xC1);
imagefilledrectangle($im, 0, 0, 50, 20, $bgColor);
$font_file = 'truetype/arial.ttf';
//Add some text
imagefttext($im, 11, 0, 6, 11, $txt, $font_file, $captcha);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
ASKER
This does not work.
<?php
//test.php
//Include the standard head
require('includes/applicat ion_top.ph p');
$_SESSION['captcha'] = rand()%9 . rand()%9 . rand()%9 . rand()%9 . rand()%9;
//Print an image
<?php echo '<img src="captcha.php" width="50" height="11"/>' ?>
?>
<?php
//captcha.php
//Include the standard head
require('includes/applicat ion_top.ph p');
//Create an image
$im = imagecreatetruecolor(50, 11);
$bgColor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$txt = imagecolorallocate($im, 0x00, 0x76, 0xC1);
imagefilledrectangle($im, 0, 0, 50, 20, $bgColor);
$font_file = 'truetype/arial.ttf';
//Add some text
imagefttext($im, 11, 0, 6, 11, $txt, $font_file, $_SESSION['captcha']);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
<?php
//test.php
//Include the standard head
require('includes/applicat
$_SESSION['captcha'] = rand()%9 . rand()%9 . rand()%9 . rand()%9 . rand()%9;
//Print an image
<?php echo '<img src="captcha.php" width="50" height="11"/>' ?>
?>
<?php
//captcha.php
//Include the standard head
require('includes/applicat
//Create an image
$im = imagecreatetruecolor(50, 11);
$bgColor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$txt = imagecolorallocate($im, 0x00, 0x76, 0xC1);
imagefilledrectangle($im, 0, 0, 50, 20, $bgColor);
$font_file = 'truetype/arial.ttf';
//Add some text
imagefttext($im, 11, 0, 6, 11, $txt, $font_file, $_SESSION['captcha']);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
ASKER
This does work.
<?php
//test.php
//Include the standard head
//require('includes/application_top.php');
$_SESSION['captcha'] = rand()%9 . rand()%9 . rand()%9 . rand()%9 . rand()%9;
//Print an image
<?php echo '<img src="captcha.php" width="50" height="11"/>' ?>
?>
<?php
//captcha.php
//Include the standard head
//require('includes/application_top.php');
//Create an image
$im = imagecreatetruecolor(50, 11);
$bgColor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$txt = imagecolorallocate($im, 0x00, 0x76, 0xC1);
imagefilledrectangle($im, 0, 0, 50, 20, $bgColor);
$font_file = 'truetype/arial.ttf';
//Add some text
imagefttext($im, 11, 0, 6, 11, $txt, $font_file, $_SESSION['captcha']);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
ASKER
In the three examples above I use.
1. The osc way to set a session var
2. I use the standard PHP way with the "require('includes/applica tion_top.p hp');"
3. I use the standard PHP way without the "require('includes/applica tion_top.p hp');"
The middle way should work but the osc header seems to destroy the session. I've checked the code and I can't see why. I wondered if anybody had similar experience and had fixed it.
Kind Regards,
Adrian Smith
1. The osc way to set a session var
2. I use the standard PHP way with the "require('includes/applica
3. I use the standard PHP way without the "require('includes/applica
The middle way should work but the osc header seems to destroy the session. I've checked the code and I can't see why. I wondered if anybody had similar experience and had fixed it.
Kind Regards,
Adrian Smith
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Ray
I'll have a go tomorrow. I'm rushing to finish something.
Kind Regards,
Adrian Smith
I'll have a go tomorrow. I'm rushing to finish something.
Kind Regards,
Adrian Smith
ASKER
I'm still looking into this.
I found the following code snippet (Q_24191944.html) which is as Ray says but is a little more prescriptive.
I found the following code snippet (Q_24191944.html) which is as Ray says but is a little more prescriptive.
echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
ASKER
Many thanks for your help Ray. I tried the var_dump($_SESSION) method and my private sessions are fine. The only problem I have is when I try to call a GD image and pass the session too it. Anyway. I'm not really bothered any more because the osCommerce method I used above works fine. If I need to find a solution in the future I'll add it to the end of this post.
Anybody finding this post and wanting a solution - use the method at the top that I say is the one that works.
Many Thanks,
Adrian Smith
London
Anybody finding this post and wanting a solution - use the method at the top that I say is the one that works.
Many Thanks,
Adrian Smith
London
Thanks for the points. Your comments are helpful, too, in making this a good one for the PAQ.
best, ~Ray
best, ~Ray
Have you verified that the sessions are working right on the server?