shadiadiph Posted June 19, 2009 Share Posted June 19, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/ Share on other sites More sharing options...
wildteen88 Posted June 19, 2009 Share Posted June 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859792 Share on other sites More sharing options...
shadiadiph Posted June 19, 2009 Author Share Posted June 19, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859794 Share on other sites More sharing options...
shadiadiph Posted June 19, 2009 Author Share Posted June 19, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859798 Share on other sites More sharing options...
wildteen88 Posted June 19, 2009 Share Posted June 19, 2009 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']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859803 Share on other sites More sharing options...
shadiadiph Posted June 19, 2009 Author Share Posted June 19, 2009 ok i kind of uderstand what you mean but before it was working is there anyway i can creat $username $password from this <?php session_start(); echo $_SESSION['username']; echo $_SESSION['password']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859813 Share on other sites More sharing options...
shadiadiph Posted June 19, 2009 Author Share Posted June 19, 2009 reaosn being is i have a script runnign from a required page that uses $sql="SELECT * FROM tbladmin WHERE adminuser='$username' and adminpass='$password' and logged='Yes' and dtlogged='$validdt'"; Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859817 Share on other sites More sharing options...
shadiadiph Posted June 19, 2009 Author Share Posted June 19, 2009 solved it thankyou Quote Link to comment https://forums.phpfreaks.com/topic/162953-solved-php-is-killing-session-variables/#findComment-859828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.