
Originally Posted by
chris.upjohn
Off Topic:
On a side note I always try to move users away from AJAX logins as you need SSL to truly lock down the connection between the client and server since man in the middle attacks are easy to accomplish with forms like this
Thanks very much for the rely. I'd to get something setup for for testing and learning.
How about something like this at the top of my index page:
PHP Code:
<?php
if( $_SESSION['auth'] != 1 ) {
require( 'login.php' );
break;
}
?>
Login.php
PHP Code:
<?php
$name = $_POST['name'];
$pass = $_POST['pass'];
if( isset($name) || isset($pass) )
{
if( empty($name) ) {
var fancyContent = ('<div class="header"><p>please enter a name</p></div>');
$.fancybox({ content: fancyContent });
}
if( empty($pass) ) {
var fancyContent = ('<div class="header"><p>please enter a password</p></div>');
$.fancybox({ content: fancyContent });
}
if( $name == "correct" && $pass == "correct" )
{
// Authentication successful - Set session
session_start();
$_SESSION['auth'] = 1;
setcookie("username", $_POST['name'], time()+(84600*30));
var fancyContent = ('<div class="header"><p>Access granted</p></div>');
$.fancybox({ content: fancyContent });
}
else {
var fancyContent = ('<div class="header"><p>Incorrect username or password!"</p></div>');
$.fancybox({ content: fancyContent });
}
}
// If no submission, display login form
else {
include('loginform.php')
break;
}
?>
Bookmarks