Jump to content

Recommended Posts

Dont' know why but my ISP's server went down and they have reinstalled it yesterday but php now kills all session variables stone dead I have been trying to tell them all the bugs but they are not sure what is causing this. For example I start a session enter $username and $password but when i get to the next page $username and $password have no value this is not a $_POST problem that part works fine but we are wondering what is killing the session?

Link to comment
https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/
Share on other sites

You need to post your code to identify the issue. Post the parts where you define/use your session variables. However I have a feeling it is because your code is relying on depreciated settings which are now disabled by default on new installations.

ok for example

 

the login script

 

<?PHP
session_start();
error_reporting(7);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<body>
<form name="login" method="post" action="test.php">
<input type="hidden" name="ipaddress" value="<?=$ipaddress?>" />

<table class="login">

<tr><td class="head">USERNAME</td></tr>

<tr><td><input type="text" name="username" maxlength="14" value="" /></td></tr>
<tr><td class="head">PASSWORD</td></tr>
<tr><td><input type="password" name="password" maxlength="9" /></td></tr>
<tr><td class="button"><input type="submit" name="submit" value="Login" /></td><td> </td></tr>
</table>
</form>	

 

test.php i set up usually it posts and registeres a session but just for simplicity

 

<?php
session_start();
$username = $_POST['username']; 
$password = $_POST['password']; 
print $username;
print $password;
?>
<html>
<body>
<a href="test2.php">test</a>
</body>
</html>

 

then variables in the session appear to have dissappeared when i link to test2.php

 

<?php
session_start();
print $username;
print $password;
?>

 

this one displays nothing $username and $password do not exist any more the session has not been destroyed anywhere before the variables would be set and passed from page to page in te browser session until they were unset or destroyed but right now it is just killing them stone dead??

dont know if this is relevant but on phpinfo the session part is set up lke this

session
Session Support  enabled  
Registered save handlers  files user sqlite  
Registered serializer handlers  php php_binary  

Directive Local Value Master Value 
session.auto_start Off Off 
session.bug_compat_42 On On 
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_httponly Off Off 
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 100 100 
session.gc_maxlifetime 1440 1440 
session.gc_probability 1 1 
session.hash_bits_per_character 4 4 
session.hash_function 0 0 
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_only_cookies Off Off 
session.use_trans_sid 0 0 

You're not using sessions properly. Global variables do not get passed to other pages.

 

You need to use the $_SESSION superglobal to assign/use session variables.

 

In test.php you'd use

<?php
session_start();
$username = $_POST['username']; 
$password = $_POST['password']; 

// assign username/password to session
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

print $username;
print $password;
?>

 

Now to retrieve your session variables in test2.php you'd use

<?php
session_start();
echo $_SESSION['username'];
echo $_SESSION['password'];
?>

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.