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
lwfukAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
PHP Sessions, by default, may not be set in such a way that PHP can find them across sub-directories or sub-domains - there is a special was you need to set the session cookie to get this to work reliably.

Have you verified that the sessions are working right on the server?
0
lwfukAuthor Commented:
Hi Ray

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

Open in new window

0
lwfukAuthor Commented:
Actually ignore the above. I'll put together a better demo.
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

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

Open in new window

0
lwfukAuthor Commented:
This does not 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);

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

Open in new window

0
lwfukAuthor Commented:
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/application_top.php');"
3. I use the standard PHP way without the "require('includes/application_top.php');"

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
0
Ray PaseurCommented:
Hmm.  Have you tried using var_dump($_SESSION) before and after the "require('includes/application_top.php');"

Might be a clue there.  Use echo "<pre>\n"; to make the var_dump more readable.
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lwfukAuthor Commented:
Hi Ray

I'll have a go tomorrow. I'm rushing to finish something.

Kind Regards,

Adrian Smith
0
lwfukAuthor Commented:
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.

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

Open in new window

0
lwfukAuthor Commented:
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
0
Ray PaseurCommented:
Thanks for the points.  Your comments are helpful, too, in making this a good one for the PAQ.

best, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.