Hi all,
I can't seem to get my sessions to work and after having spent a couple of hours searching the forums and recoding but still haven't sorted it out.
I am trying to set a session with the user login information submitted by a form and checked against a database. My login form sends the info to a validation file where I had hoped to set the session variable. If the login is not correct the user is redirected back to an error page.
I also have a sessionFile.php where I have stored the code to check if the session is not set, which I want to include on each page to prevent a user accessing the page without logging in.
I am using an ODBC connection to an Access database and I know the connection is ok because all my other code is working fine.
Here is my code for the Validation page:
<?
session_start();
ob_start();
include ("connectionData.php");
$Login = $POST['login'];
?>
<?
$sql="select * from Settings where Login = '$Login'";
$rs=odbc_exec($conn, $sql);
$numrows = odbc_fetch_row($rs);
if ($numrows == 0){
header("Location: defaultLogin.php");
exit;}
else
{
$SESSION['Login'] = $_POST['login'];
}
exit;
?>
Here is my include file code:
<?php
if (!isset($SESSION['Login']) OR $SESSION['Login'] == "") {
header('Location: index.php');
}
?>
This is how I have included my files on the other pages:
<?
session_start();
include("sessionFile.php");
include("connectionData.php");
?>
When I try and log in I keep getting re-directed to the login page, so the session ['Login'] isn't being set. Also if I try to echo SESSION_['Login'] on the other pages I get nothing.
I have made sure session_start() is the first thing on each page. Any ideas on what the problem could be would be greatly appreciated!!
Ta.
ps. How do I get my code to appear in those snazzy colour coded boxes on these forums?