I'm building a login & auth for my site. The form should send the username and password to auth.php, check db then create a session to store the username and usergroup. THen redirect back to the index.php.
All of this work except for the session values not being set across. I have created test session variables to see if they are sent to the other page but they don't.
<?php // index.php
session_start();
header("Cache-control: private");
echo $_SESSION["username"];
if ($_SESSION["username"] == "") {
include 'includes/login_form.php';
}
?>
<?php // auth.php
session_start();
header("Cache-control: private");
$username = $_GET['username'];
$password = sha1($_GET['password']);
mysql_connect("localhost","root","");
mysql_select_db("testcms");
$auth = mysql_query("SELECT `username` , `password` , `usergroup`
FROM `users`
WHERE `username` = CONVERT( _utf8 '$username'
USING latin1 )
COLLATE latin1_swedish_ci
AND `password` = '$password'
COLLATE latin1_swedish_ci
LIMIT 0 , 1");
while($r=mysql_fetch_array($auth))
{
$_SESSION["username"] = $r[username];
$_SESSION["usergroup"] = $r[usergroup];
}
header("Refresh: 5; url=../index.php");
?>