Posts: 427
Name: Stuart
Location: Glasgow, Scotland
|
hey
Im trying to create a login script using sessions, ive got a documentation about sessions and it all seemed pretty straight forward, but im having trouble with it not recognising the session stored variable in other scripts. Below is the code im using...
Login Page:
PHP Code:
<?php
session_start();
include("admin_setup.php");
include("admin_colour_scheme.php");
include("admin_top.php");
include("admin_login_sidelinks.php");
?>
///HTML omitted
if(isset($_GET['team_id'])){
//code omitted showing log in screen text boxes etc if form not processed yet
} elseif(isset($_POST['username'])&& isset($_POST['password']) && isset($_POST['team_id'])) {
$username_submit = $_POST['username'];
$password_submit = $_POST['password'];
$team_id_submit = $_POST['team_id'];
$result = mysql_query("SELECT * FROM account WHERE id='$team_id_submit'");
$num_rows = mysql_num_rows($result);
$result_rows = mysql_fetch_array($result);
$name = $result_rows['name'];
$username = $result_rows['username'];
$password = $result_rows['password'];
if(($username == $username_submit) && ($password == $password_submit)) {
session_register("logged_on");
$logged_on = "1";
print "Welcome $name, You've successfully logged into your Team Lines Admin Centre";
print "<br>";
print "<br>";
print "You will be redirected to the Admin Centre in 5 seconds...";
print "<br>";
print "<br>";
print "or click <a href=\"admin_account.php?team_id=$team_id_submit\">here</a> to proceed to the Admin Centre";
} else {
print "Sorry, but the Username and/or Password you supplied was incorrect. Please go <a href=\"javascript:history.back(-1)\">back</a> and try again.";
}
}
?>
Checking if user is logged in on admin pages...
PHP Code:
<?php
session_start();
if($logged_on == "0"){
header( "Location: login.php?team_id=$team_id");
}
?>
I hope this makes sense to someone at least, and i appreciate any comments.
Cheers
Stoot
PS im using PHP v 4.3.3 and Apache 1.3.27 if maybe i have settings to change.
|