Board index   FAQ   Search  
Register  Login
Board index PHP PHP Installation

Sessions with PHP

Forum for you who has PHP installation issues

Moderators: macek, egami, gesf

Sessions with PHP

Postby mike_robb » Sat Jun 12, 2004 5:12 pm

I've been using PHP sessions for some time on a public web server.

Recently I installed Redhat 9 / Apache and PHP on a local PC [on my LAN].

PHP 4.3.6 [from terminal > php --version]
PHP 4.2.2 [from Apache via phpinfo() test page]
Apache 2.0.40

With this test session code:
Code: Select all
<?
session_start();
 
if(isset($HTTP_POST_VARS['inputName']))
{
  $Name=$HTTP_POST_VARS['inputName'];
}
 
$nameIs=0;
if($_SESSION["Name"]){$nameIs+=1;}
if($HTTP_SESSION_VARS["Name"]){$nameIs+=4;}
 
$Count++;
session_register("Name");
session_register("Count");
?>
<html>
<body>
<?
$SID=session_id();
echo "session name: ".session_name()."<BR>\n";
echo "session id: ".session_id()."<BR>\n";
echo "session module name: ".session_module_name()."<BR>\n";
echo "session save path: ".session_save_path()."<BR>\n";
echo "encoded session: ".session_encode()."<BR>\n";
 
 
if($Name!=""){echo "Hello $Name<BR>";}
 
echo "You [ $Name ] have been here $Count times.<BR>\n";
 
echo "<form action='$SCRIPT_NAME?".$SID."' METHOD=POST>";
echo "<input name='inputName' value='$sess_name'><BR>";
echo "<input type=submit>";
echo "<a href='$SCRIPT_NAME?".$SID."'>Reload Page</a>";
 
?>
<HR>
NameIs=<?=$nameIs;?>



If I load up the page and enter "blah" and submit, it will store into the /tmp/sess* file this:
Name|s:4:"blah";Count|i:1;


But it will never update it from there, the count remains 1 etc. I can delete the file, or destroy the session and then it will store the new posted data.

any help would be grealy appreciated. pointers or suggested reading is fine too :)

also here is the phpinfo() output section for the session stuff:
session
Session Support enabled

Directive Local Value Master Value
session.auto_start
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_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 /tmp
session.serialize_handler
php php
session.use_cookies
On On
session.use_trans_sid
1 1
mike_robb
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Jun 12, 2004 4:56 pm
Location: Dallas, TX (USA)

Postby Redcircle » Sun Jun 13, 2004 12:01 am

You do not need to use session_register anymore. After you call session_start() $_SESSION is just a normal array.


Also you can use $_POST instead of $HTTP_POST_VARS

I think you are confusing yourselft by using 2 different methods of handling sessions and predefined variables.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby mike_robb » Sun Jun 13, 2004 6:10 am

thanks for the tips. i'll give it a go. :)
mike_robb
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sat Jun 12, 2004 4:56 pm
Location: Dallas, TX (USA)


Return to PHP Installation

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.