Fedora Linux Support Community & Resources Center
  #1  
Old 8th November 2004, 11:06 PM
wjudy Offline
Registered User
 
Join Date: Sep 2004
Posts: 10
php Session vars passing

Hi,
Please help solve my problem about session vars passing between pages

Env: Fedora 2 with php 4.3.8 & mysql

F1.php --- page1
<?php
session_start();
$conn=mysql_connect('host','usr','pw');
if (!$conn) die(....);
mysql_select_db('mydb',$conn);
$result = mysql_query(.....); #successfully create temporary table

$_SESSION['db_conn'] = $conn;
$_SESSION['pt_code'] ='yahoo2';
?>

F2.php ---page2
<?php
session_start();
echo 'db_conn=' .$_SESSION['db_conn'] . '<br>';
echo 'pt_code=' .$_SESSION['pt_code'] . '<br>';

?>

Result from page2:
db_conn=
pt_code=
This means the session vars are not passed.

But I read session file in /tmp as following:

db_conn|i:0;pt_code|s:6:"yahoo2";

What's wrong?
Reply With Quote
  #2  
Old 8th November 2004, 11:24 PM
IceNine's Avatar
IceNine Offline
Registered User
 
Join Date: Oct 2004
Location: Carlsbad, CA
Age: 29
Posts: 93
try a
PHP Code:
print_r($_SESSION); 
on page 2
__________________
Did I help? Add to my reputation! And please... DON'T ask why I'm a Slacker. ;)
Reply With Quote
  #3  
Old 8th November 2004, 11:40 PM
wjudy Offline
Registered User
 
Join Date: Sep 2004
Posts: 10
Hi, IceNine:
Thanks for your help.
I tried. the result is "Array()"

Reply With Quote
  #4  
Old 8th November 2004, 11:48 PM
IceNine's Avatar
IceNine Offline
Registered User
 
Join Date: Oct 2004
Location: Carlsbad, CA
Age: 29
Posts: 93
That confirms your Session vars are not being populated. Have you look at your Session ID info?
__________________
Did I help? Add to my reputation! And please... DON'T ask why I'm a Slacker. ;)
Reply With Quote
  #5  
Old 8th November 2004, 11:49 PM
IceNine's Avatar
IceNine Offline
Registered User
 
Join Date: Oct 2004
Location: Carlsbad, CA
Age: 29
Posts: 93
Also, can you show me your phpinfo()?
__________________
Did I help? Add to my reputation! And please... DON'T ask why I'm a Slacker. ;)
Reply With Quote
  #6  
Old 9th November 2004, 12:33 AM
wjudy Offline
Registered User
 
Join Date: Sep 2004
Posts: 10
Unhappy

Hi, Icenine:
I put code at begining of page2
<? php
if(!session_id())
{ session_start();
phpinfo();
}
.......

The result: it prints phpinfo
Then I check the session dir, find the web creates a lot of session files w var ids, even I keep in one log session. That means it creats one session for each page. Why?

phpinfo:


HTTP Response Headers
X-Powered-By PHP/4.3.4
Set-Cookie PHPSESSID=00a5940a69c1791acb51dee1202ca2d2; path=/
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Connection close
Transfer-Encoding chunked
Content-Type text/html; charset=UTF-8

Session Support enabled
Registered save handlers files user

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /tmp/php/session /tmp/php/session
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off

Last edited by wjudy; 9th November 2004 at 01:13 AM.
Reply With Quote
  #7  
Old 9th November 2004, 07:28 PM
wjudy Offline
Registered User
 
Join Date: Sep 2004
Posts: 10
hi,
Thanks IceNine, I followed the direction to trace. but I still can solved the problem. Even turn on client side cookie. sessionID sent by header. Where is the sessionID saved?
in my page1 code:
<?php
session_cashe_limiter('private_no_expire');
session_set_cookie_params(0,'/tmp');
session_start();
....
?>
Is it sessionID saved in client-side cookie area? If yes, why not use pure cookie instead of session?
If not, where is it saved ? Can i see it?
in my 2nd page:
<? php
if (!seesion_id())
{ session_start();
echo phpinfo();
}
....
?>
it always get in if block. creating a new sessionID.
I am very dummy. Please help!
Thanks
Reply With Quote
  #8  
Old 9th December 2004, 02:35 PM
dlightle Offline
Registered User
 
Join Date: Dec 2004
Posts: 3
I don't know if you copy-pasted this or if you re-typed it, but you have a typo that would significantly effect the output:

Code:
in my 2nd page:
<? php
if (!seesion_id()) 
{ session_start();
echo phpinfo();
}
Also, in this code:

Code:
F1.php --- page1
<?php
session_start();
$conn=mysql_connect('host','usr','pw');
if (!$conn) die(....);
mysql_select_db('mydb',$conn);
$result = mysql_query(.....); #successfully create temporary table

$_SESSION['db_conn'] = $conn;
$_SESSION['pt_code'] ='yahoo2';
?>
You might add an echo line for the $conn just before you store it in the session. I'm definitely no pro at PHP, but I have had sessions working once. Your code looks like it should work at a glance, though. You might also try commenting out lines more and more, limiting the other factors until you end up with the most minimal lines (ie. just the session assignments). Then you can work backwards to see what is wrong.

Last edited by dlightle; 9th December 2004 at 02:41 PM.
Reply With Quote
Reply

Tags
passing, php, session, vars

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set vars in %post from boot prompt pileofrogs Installation and Live Media 0 18th February 2005 08:15 PM


Current GMT-time: 01:30 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat