PHP session index undefined after header redirection? -


i have struggled hours can't work. when redirection php page, session variables null. on xampp server.

session.php

<?php      session_start();      if(isset($_post['submitted']))                                                                                               {            $_session['first_name'] = "max";         var_dump($_session);         header("location: http://localhost:8080/secure login/session2.php");              die();      } ?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"         "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-    1" />      <title>you logged in</title>  </head>  <body>      <form action="session.php" method="post">         <div align="center"><input type="submit" name="submit" value="login" /></div>     <input type="hidden" name="submitted" value="true" />     </form> </body> </html> 

session2.php

<?php     session_start(); ?>  <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">  <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />      <title>you logged in</title>  </head>  <body>      <div id="main">          <?php              echo '<pre>' . print_r($_session, true) . '</pre>';             echo 'you welcome session2.php <br></br>';              if (isset($_session['first_name']))              {                  echo $_session['first_name'] . "<br></br>";             }             else             {                 echo "your session doesn't exist. hate php <br></br>";                 echo $_session['first_name'];             }         ?>     </div>  </body>  </html> 

the session doesn't save, , output is;

array ( ) welcome session2.php session doesn't exist. hate php notice: undefined index: first_name in c:\xampp\htdocs\secure login\session2.php on line 28 

i have tried other things changing session variables saved xampp/tmp directory, didn't solve problem. have program need keep user logged in when redirection has blocked me more day.

update:

the space between directories wasn't problem, temporarily solved problem because there wasn't cache new directory yet. way, few more days, debugged , realized running 2 programs on localhost. both using sessions, , if 1 terminates session, terminates session other since localhost domain name , there exists 1 session. particularly, logout.php of other program not destroying session rather jumbling have remove browser cache unjumble it. emptying session array, destroying session, , destroying cookie, problem , couldn't login again. had destroy session only;

see -> killing off global session variable logout button

seems having problem because have space in name secure login

localhost:8080/secure%20login/session.php  

so please try change name underscore secure_login , change code

<?php      session_start();      if(isset($_post['submitted']))                                                                                               {            $_session['first_name'] = "max";         var_dump($_session);         header("location: http://localhost:8080/secure_login/session2.php");              die();      } ?> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -