...

View Full Version : Session Problem



Ice725
12-23-2003, 07:20 AM
I want to start a session on a page, assign a value to a session variable then display it on another page. I've broken it down as simple as possible, and I still can't get it to work!!

Page 1



<?
session_start();
$_SESSION['value'] = "Hello World";

?>


Page 2



<?
session_start();
echo $_SESSION['value'];
?>


Only value I changed in the php.ini was

session.save_path = C:\temp

Can anyone offer any advice to get me goin?

Ice725
12-23-2003, 07:44 AM
I'm using version 4.3.4 and phpinfo() says Session Support is enabled.

raf
12-23-2003, 03:23 PM
Welcome here.

I have no idea, based on the code you showed, i'd suspect it to work.

Maybe 'value' isn't the most sensible variablename you could choose but i doubt if that is the problem (but you soon findout ifyou change it). Is there any other code in these pages? If so,try moving these lines to the very top of your script on both pages.

Ice725
12-23-2003, 09:24 PM
I look inside the session files and I can see

myvar|s:9:"Hello";

So this tells me its writing variable myvar, but I just can't get it to read properly. Any advice? I've tried reinstalling PHP. I dont want to use an older version of php... do I?

code4food
12-27-2003, 12:01 AM
The problem may be in how you are transitioning from page 1 to page2. Specifically, if you are using a header() call you must supply a fully qualified URL, meaning give a complete URL specification to the header such as

header( 'Location: http://www.yourdomain.com/path_to_web_page' )

I had trouble with only supplying relative paths to web pages and session variaibles.

raf
12-27-2003, 12:07 AM
Indeed. You can dynamically build these like:


header('Location: http://'.$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
.'/filename.php');

This way, the redirect will generate a call to the webserver. I suppose i will only matter if you have cookies disabled, because the sessionID then need to be added to each request. With a serverside redirect, this iw probably not the case (not sure though)

Also, try renaming the sessionvariable --> if you have another variable called "$value", then your code will not work on certain servers. (I know i have that problem with one of my hosts)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum