This is my first post here. G'day everyone. I'm having trouble with getting a session recognized from one page to another. I did a search and used the advice but I'm still having trouble.
I have a page called checklogin.php that processes the information submitted for a member to login, and redirect it to login_success.php if the login was successful.
The problem I have is when I test the session in the second page it tells me there is no session. Here's my code (I omitted the db connection code):
<?php
// username and password sent from form
$myusername=$_POST['user'];
$mypassword=$_POST['pass'];
?>
<?
// 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['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
after I am redirected to login_success.php:
<?php
session_start();
$_SESSION['myusername'];
if (isset($_SESSION['myusername']))
{
$loggedin = TRUE;
return $loggedin;
echo "logged in.";
}
else
echo "not logged in";
?>
It echoes "not logged in". I've struggled with this for days and I don't know what's wrong. Thanks in advance.