session variable problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevin_bkk
Forum Newbie
Posts: 5
Joined: Fri Jul 19, 2002 12:27 pm

session variable problem

Post 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
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Cookie based

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
kevin_bkk
Forum Newbie
Posts: 5
Joined: Fri Jul 19, 2002 12:27 pm

Re: Cookie based

Post 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
kevin_bkk
Forum Newbie
Posts: 5
Joined: Fri Jul 19, 2002 12:27 pm

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply