Hey guys im struggling to pass a session in php, i cant quite figure out why though.
My friend used the exact same code as me but it doesnt want to work.
This code is the database checker (which seems to work) maybe im over looking some thing??
<?php
session_start();
$host="localhost"; //host name is localhost
$tbl_select="tbluser"; // Table name
// Connect to server and select databse.
$db=mysql_connect('localhost', 'us8', 's8');
$db_selected=mysql_select_db('dbs8', $db);
$myUserName=$_POST['username'];//store the username from the form in the variable myusername
$myPassword=$_POST['password'];//store the password from the form in the variable mypassword
// To protect MySQL injection....
$myUserName = stripslashes($myUserName);
$myPassword = stripslashes($myPassword);
$myUserName = mysql_real_escape_string($myUserName);
$myPassword = mysql_real_escape_string($myPassword);
//select user
$sql="SELECT * FROM $tbl_select WHERE username='$myUserName' and password='$myPassword'"; //get the username and password form the table user
$result=mysql_query($sql); //store the username and password in variable result
$count = mysql_num_rows($result); // count the number of rows in the result
if ($count==1) // if there is 1 row
{
$_SESSION['myUserName']=$myUserName;
$_SESSION['loggedIn']="true"; //they are logged in
// setcookie("myUserCookie", $myUserName, time()+3600); set a cookie called myUserCookie with the value of username which expires in an hour
header('Location: test1.php'); //they are redirected back to the homepage
}
else
{
/*session_unset(); //get rid of session values
session_destroy(); //destroy the session
header('Location:index.php'); //redirect back to the home page*/
echo "Nah";
}
?>
and this is the code snippet that im having a problem with (it doesnt want to take the login area away if the user is logged in)
<?php
//checking whether logged in...
if (isset($_SESSION['loggedIn']))
{
echo "<table align='right'><form name='logOut' method='post' action='logout.php'><tr><td>Hi S11 you are currently logged in</td></tr><tr><td>1 is your user ID</td></tr><td><input type='submit' name='submit' value='Log Out'></td></form></table> </div><!--closes login-->";
}
else if (!isset($_SESSION['loggedIn']))
{
echo "<table align='right'>";
echo "<form name='login' method='post' action='test.php'><tr>";
echo "<td>User Name</td>";
echo "<td><input name='username' type='text' id='username' /></td>";
echo "<td>Password</td>";
echo "<td><input name='password' type='password' id='password' /></td>";
echo "<td colspan='2'><input type='submit' name='Submit' value='Login' /></td>";
echo "</tr>";
echo "</form>";
echo "</table>";
}
?>