I have a login page (index.php) with a form that submits to process_memberlogin.php which then sends to user to the members page if successful. That works, login works, no problemo. Now im attempting to create a session variable which each member page checks to be valid. Also no big deal.
Problem is im getting the error "Cannot send session header already sent blah blah". I checked for whitespace, output, etc and everything is where it should be. Only thing i can figure is posting the variable from index to process_memberlogin is the problem. Am i right? I tried posting index to itsself and passing username and password via session as well, but made no difference.
index has this at the top
<?php session_start(); ?>
And then has the form, and posts to the process file. Process file contains
<?php
session_start();
/*
This file process's the member logins
Developers Note:
Need to add redirection to members home when ready.
Add check for wrong password
*/
include('Connections/establish_dbconn.php');
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("$database_ASA") or die(mysql_error());
$sql = "SELECT username , password FROM test_members WHERE username='$username' AND password='$password'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
}
$num_rows = mysql_num_rows($r);
if($num_rows > 0){
//echo ("successfully logged into system.");
//proceed to perform website’s functionality – e.g. present information to the user
$_SESSION['MM_Username'] = $username;
header("Location: member_home.php");
}
else{
//echo ("no such login in the system. please try again.");
$_SESSION['MM_Username'] = "";
header("Location: index.php");
}
?>
Which on successful routes to the member home, which has (at the top):
<?php session_start();
if (!(isset($_SESSION['MM_Username']) && $_SESSION['MM_Username'] != '')) {
header ("Location: login.php");
}
?>