Squawkers13 wrote:
A user login system
I use this code for user login
"login.php"
<?php
session_start();
if(isset($_SESSION["username"])){
session_destroy();
Header("Location:mainpage.php");
}else{
echo "<html><head><title>login</title></head><body>";
echo "<form action='login2.php' method='post'>";
echo "username:<input type='text' name='username'><br/>";
echo "password:<input type='password' name='password'><br/>";
echo "<input type='submit' value='login'>";
echo "</forum></body></html>";
}
?>"login2.php"
<?php
session_start();
$response = trim(file_get_contents('http://scratch.mit.edu/api/authenticateuser?username=' . $_POST['username'] . '&password=' . $_POST['password']));
if($response == 'false'){
session_destroy();
echo "wrong username or password <a href='login.php'>try again</a>";
} else {
$parts = explode(':', $response);
if ($parts[2] == "unblocked"){
$_SESSION["username"]=$_POST['username'];
Header("Location:mainpage.php");
}
}
?>and I put this code in all my protected pages:
<?php
if(!isset($_SESSION["username"])){
Header("Location:login.php");
}
?>does this help ? example
Last edited by dvd4 (2012-09-11 15:52:53)
Offline