I have “frankensteined” this code from multiple tutorials, and it works for me, but I am having to log in TWICE!(after link is clicked upon successful login, it returns to the login page). Below is my code:
Login.php
[php]
<?php
@session_start();
include (‘mysql.php’);
if (isset ($_POST[‘submit’])) {
$username = mysql_escape_string($_POST['username']);
$password = mysql_escape_string($_POST['password']);
if (!empty ($username) && !empty ($password)) {
$sql = mysql_query ("SELECT * FROM users
WHERE username='".$username."' AND
user_password='".$password."' LIMIT 1");
if (mysql_num_rows ($sql) > 0) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
echo "<a href='http://g2comics.com/battles/battlesonline.php'><h2>YOU MAY NOW ENTER</h2></a>";
} else {
echo 'Your username and/or password is incorrect!';
}
} else {
echo 'You must enter a username and password!';
}
} else {
echo ’
Username:
Password:
?>
Battlesonline.php (members page)
[php]<?php
session_start();
if ($_SESSION[‘loggedin’] == true) {
echo ‘Welcome, ‘.$_SESSION[‘username’].’, to the member’s only page!’;
} else {
header( ‘Location: http://g2comics.com/battles/login.php’ ) ;
}
?>
G2 Comics-Battles Online [/php]Everything else is set up correctly. Let me know if i need to add any more info. Thanks.