Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: $_SESSION variables not passing to another file
    primarykey
    data
    text
    <p>I'm currently learning to work with sessions and alike things, and I'm trying to make some simple log-in system, but I can't seem to pass variables from one page to the next.</p> <p>login_confirm.php</p> <pre><code>&lt;?php session_start("session"); $host="localhost"; // Host name $username="*"; // Mysql username $password="*"; // Mysql password $db_name="*"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=hash('sha256', $_POST['mypassword']); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); $_SESSION['_username']=$myusername; header("location:login_success.php"); } else { echo "Wrong Username or Password."; } ob_end_flush(); ?&gt; </code></pre> <p>login_success.php</p> <pre><code>&lt;?php session_start(); if(!session_is_registered(myusername)){ //header("location:login.php"); echo $_SESSION['_username']; } ?&gt; </code></pre> <p>Basically it wont even echo the <code>$_SESSION['_username'];</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload