Page 1 of 1

session variable problem

Posted: Fri Jul 19, 2002 12:27 pm
by kevin_bkk
dear sir ,
iam try to create and pass the session variable
using PHP, but i could not able to pass the session variable from one page to another page through server.
my problem is that i create a session variable by following code and save it in silicon-bay.com/session.php

<?php

session_start();
$my_session_variable = "some value";
session_register("my_session_variable");

?>
than i call the session variable in silicon-bay.com/session1.php by inserting the following code

<?php

session_start();
print "Value of 'my_session_variable':$my_session_variable";

?>
now on both the pages i dont find any error
but ultimately on session1.php the variable value is not displayed
i dont know why, iam going mad please help me,
i discussed this with my hosting company but they tell me when they tested the same pages in there computer they see the value of the variable properly means they are telling that the script works fine in there computers, so if they can see the value why i cannot see the value
i have tried checking it on all windows platfrom and at least more than 10 computer but i cant see it,
and with my hosting computer guys can read see the value. they tried it with an external dialup connect too it display the value.
here it gives me the session ID on next page but the variable which i register is not seen
please help :roll:
so please help me out

Cookie based

Posted: Fri Jul 19, 2002 3:49 pm
by EricS
You are not explicitly passing the SID in the URL, so all pc's that don't have cookies enabled will not be able to take advantage of sessions.

Pass the SID in the URL like this

Code: Select all

silicon-bay.com/session1.php?<? echo SID ?>
That should fix your problem.

Posted: Sat Jul 20, 2002 5:08 am
by twigletmac
session_register() doesn't work with register_globals off. It's possible that it's off on some of the computers you are testing this code on and not on others try:

Code: Select all

<?php 

session_start(); 
$HTTP_SESSION_VARS&#1111;'my_var'] = 'some value'; 

?>
and in session1.php

Code: Select all

<?php 

session_start(); 
echo '$my_var: '.$HTTP_SESSION_VARS&#1111;'my_var']; 

?>
You don't say which version of PHP you are using, if it is version 4.1 or above you can replace $HTTP_SESSION_VARS with $_SESSION.

Mac

Re: Cookie based

Posted: Sat Jul 20, 2002 2:20 pm
by kevin_bkk
EricS wrote:You are not explicitly passing the SID in the URL, so all pc's that don't have cookies enabled will not be able to take advantage of sessions.

Pass the SID in the URL like this

Code: Select all

silicon-bay.com/session1.php?<? echo SID ?>
That should fix your problem.
thanks for reply ,sir for you above suggustion , i tried inserting the above script
the result what i got in address bar was

http://www.silicon-bay.com/session1.php ... f39baef329

but ultimately i could not see the value of the variable in the session1.php page.
any more suggustion

Posted: Sat Jul 20, 2002 2:23 pm
by kevin_bkk
twigletmac wrote:session_register() doesn't work with register_globals off. It's possible that it's off on some of the computers you are testing this code on and not on others try:

Code: Select all

<?php 

session_start(); 
$HTTP_SESSION_VARS&#1111;'my_var'] = 'some value'; 

?>
and in session1.php

Code: Select all

<?php 

session_start(); 
echo '$my_var: '.$HTTP_SESSION_VARS&#1111;'my_var'];

?>
You don't say which version of PHP you are using, if it is version 4.1 or above you can replace $HTTP_SESSION_VARS with $_SESSION.

Mac
sir i did it the the way you mentioned but no results
i tried even with replacing $_session but does not displays the value

Posted: Sat Jul 20, 2002 5:11 pm
by twigletmac
You shouldn't have any whitespace or output anything else (like HTML) to the browser before the calling session_start(). So,

Code: Select all

<?php
session_start();
should be right at the top of the file with nothing before it. However, since it works on other people's computers that probably isn't the problem. Is that all the code you have in the files?

BTW, PHP is case sensitive so $_session is not the same thing as $_SESSION.

Edit: Have just been to http://www.silicon-bay.com/session.php and it all seems to be working?

Mac