Page 1 of 1

REPOST- Please Help with HTTP_SESSION_VARS

Posted: Thu Feb 06, 2003 8:18 am
by PingLeeQuan
I am stuck in figuring out a way to have HTTP_SESSION_VARS print on another page

to simplify, I have 3 screens login, request, and insert

In login I capture name and email of the person then I redirect to request


request sets the start_session() and HTTP_SESSION_VARS['mysessionname']=$email //eventually

When I am in insert, I try to echo the values of HTTP_SESSION_VARS that were set in request but I get nothing for them

anyone can shed light please?

I am using PHP 4.0.1

code in request

Code: Select all

<? session_start();
if (empty ($HTTP_SESSION_VARS&#1111;'MySessionName']) || empty ($HTTP_SESSION_VARS&#1111;'MySessionID'])  )&#123;
		
		session_name($email);
		$HTTP_SESSION_VARS&#1111;'MySessionName'] = session_name();
		$HTTP_SESSION_VARS&#1111;'MySessionID'] = session_id();
		$HTTP_SESSION_VARS&#1111;'ShoppingCartID'] = session_id();
echo $HTTP_SESSION_VARS&#1111;'MySessionID'] .'--'.$HTTP_SESSION_VARS&#1111;'MySessionName'] ;
	&#125;

?>
code in insert

Code: Select all

<? session_start();
//phpinfo();
//// THE FOLLOWING ECHO RETURNS BLANK

echo $HTTP_SESSION_VARS&#1111;'MySessionID'];

 if (empty ($HTTP_SESSION_VARS&#1111;'MySessionName']) || empty ($HTTP_SESSION_VARS&#1111;'MySessionID'])  || empty ($HTTP_SESSION_VARS&#1111;'MyUserName']) )&#123;
		session_name($email);
		$HTTP_SESSION_VARS&#1111;'MySessionName'] = session_name();
		$HTTP_SESSION_VARS&#1111;'MyUserName'] = $username;
		$HTTP_SESSION_VARS&#1111;'MySessionID'] = session_id();
		$HTTP_SESSION_VARS&#1111;'ShoppingcartID'] = session_id();
		$HTTP_SESSION_VARS&#1111;'MyCompany'] = $company;
	echo "===in log in main session id ===== ".$HTTP_SESSION_VARS&#1111;'MySessionID'].'---'.$company;		exit();
&#125;
?>
thanks in advance

Posted: Thu Feb 06, 2003 9:39 am
by volka
maybe there's an error in session-managment that isn't displayed. try

Code: Select all

<?php session_start(); 
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

...
?>
(for debugging only)

Posted: Thu Feb 06, 2003 10:20 am
by PingLeeQuan
Volka, thank you for your reply. I tried the error catch but it give me a Warning:

Code: Select all

Warning: Undefined index: MySessionID 
in /home/www/html/rfp/insert_shoppingcart.php on line 5

It does not recognize the "MySessionID" as an http_session_var.

Posted: Thu Feb 06, 2003 10:21 am
by PingLeeQuan
sorry... the code is as follows


Code: Select all

<? session_start();
error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 

echo $HTTP_SESSION_VARS&#1111;'MySessionID'];
exit();

Posted: Thu Feb 06, 2003 10:31 am
by volka
maybe I'm blind and it's simple but I don't see the error ;)

what is printed when you add

Code: Select all

echo 'session id sent: ', isset($_REQUEST[session_name()]) ? 'true' : 'false';
after each session_start(); ?
Should be "false" on the first page/doc that uses session_start() and "true" on the following.

Posted: Thu Feb 06, 2003 11:57 am
by PingLeeQuan
this is what i put in--- i am using php 4.0.1

Code: Select all

echo '<br>-HTTP_SESSION_VARS&#1111;MySessionID] =  '.$HTTP_SESSION_VARS&#1111;'MySessionID'];
echo '<br>-- HTTP_SESSION_VARS&#1111;MySessionID] =' .$HTTP_SESSION_VARS&#1111;'MySessionName'];
echo '<br>--_Request9mysessionname) = '.$_REQUEST&#1111;'MySessionName'];

echo '<br>session id sent: ', isset($_REQUEST&#1111;session_name()]) ? 'true' : 'false';

error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 
exit();
and this is the output.

Code: Select all

-HTTP_SESSION_VARS&#1111;MySessionID] = 
-- HTTP_SESSION_VARS&#1111;MySessionID] =
--_Request9mysessionname) = 
session id sent: false

Posted: Thu Feb 06, 2003 12:12 pm
by volka
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
only makes sense before the code that might produce an error ;) so put it right before session_start (if needed)
session id sent: false
indicates that there was no sessionId sent by the browser, therefor php cannot restore session data.
Probably you're using cookies to handle sessions, make sure the browser accepted them.

Posted: Thu Feb 06, 2003 12:52 pm
by PingLeeQuan
Volka, thanks again. I tried it and it still give me the same thing... nothing

I am using cookies and that works fine.
The other method (HTTP_SESSION_VARS) does not work, though.


I am setting teh session_start and the sessionVars in request.php
And i am trying to retrieve them in insertDB.php

May be i am missing the point. Do i have to be using cookies in order for me to retrieve HTTP_SESSION_VARS?

Is there a chance i can see an example (other than the manual) that already works using HTTP_SESSION_VARS without using cookies? I am not sure what i am doing wrong.

thanks again volka
--quan

Posted: Thu Feb 06, 2003 1:08 pm
by volka
there's a really simple example

Code: Select all

<?php session_start();
echo '<pre>'; print_r($HTTP_SESSION_VARS); echo '</pre>';
$HTTP_SESSION_VARS['test'] = 'value';
?>
just (re)load the page twice and $HTTP_SESSION_VARS should contain the element 'test'.
Session management is barely more than sending a (hopefully) unique value to the client that is sent back with each further request. This can be done by setting a cookie with the appropriate value or by appending it to the url.
By default php is using cookies to set the value of PHPSESSID to a unique value. Since is done automatically you do not need to set other cookies to make this work.
If you take a look into the directory specified by session.save_path (phpinfo() should show it) you will find files with names according to the different values of PHPSESSID, one for each (not already collected) session.
Create a new session by requesting your pages and then open the newly generated session-file. Does it contain the values you expect there?
If so try to enable session.use_trans_sid for testing purposes and see if it works then.
There's still the possibility that I'm really blind, not seeing a simple error....

Assuming from /home/www/html/rfp/insert_shoppingcart.php that this is a linux box of your own, so you can take the necessary actions, maybe I'm wrong ;)

read http://www.php.net/manual/en/ref.session.php to learn more about changing the configuration concerning sessions.

Posted: Thu Feb 06, 2003 2:36 pm
by PingLeeQuan
OK ... everything you talked about i understand now even better, thanks for the explanation.

I tried your snippet and it works in the file that i put it in.
Create a new session by requesting your pages and then open the newly generated session-file. Does it contain the values you expect there?
I looked in the sessid file that gets deposited on /tmp and it is empty. The file exists with the session name and id though.


While i am on the page that has the code, it works fine, But the second i go to another page and try to display the vars, it give me nothing... absolutely nothing.

thanks again for your help... i will keep playing with it until it works, Things like this bug the shxx out of me because i never declare defeat.

I just need to know why this is not working... i will let you know of my findings if you wish. May be tomorrow……


thanks a bunch for your help.
--quan

Re: REPOST- Please Help with HTTP_SESSION_VARS

Posted: Thu Feb 06, 2003 4:44 pm
by gyardleydn
PingLeeQuan wrote:

Code: Select all

<? session_start();
if (empty ($HTTP_SESSION_VARS&#1111;'MySessionName']) || empty ($HTTP_SESSION_VARS&#1111;'MySessionID'])  )&#123;
		
		session_name($email);
		$HTTP_SESSION_VARS&#1111;'MySessionName'] = session_name();
		$HTTP_SESSION_VARS&#1111;'MySessionID'] = session_id();
		$HTTP_SESSION_VARS&#1111;'ShoppingCartID'] = session_id();
echo $HTTP_SESSION_VARS&#1111;'MySessionID'] .'--'.$HTTP_SESSION_VARS&#1111;'MySessionName'] ;
	&#125;

?>
If you reread session_name() you will see that it must be called before session_start() when it sets a value

Posted: Fri Feb 07, 2003 12:08 am
by volka
outch, I am blind :roll:

Posted: Fri Feb 14, 2003 12:28 pm
by 3dron
Ping, I'm having the same problems. I have no idea what is wrong. My cookies are on, but simple session code returns nothing.

I've tried the simple print_r array test and that returns an empty array.

Let me know if you find any solution.

Posted: Mon Feb 17, 2003 2:18 am
by twigletmac
On older versions of PHP (4.0.6 and lower) I've found using the $HTTP_SESSION_VARS array to handle sessions to be very buggy. You may have to abandon this approach and use session_register() and it's associated functions instead.

Mac