Thread: web diary
View Single Post
  #4 (permalink)  
Old Aug 5th, 2007, 10:51
geyids geyids is offline
Reputable Member
Join Date: Mar 2007
Location: Kenya
Age: 19
Posts: 213
Thanks: 0
Thanked 0 Times in 0 Posts
Re: web diary

Quote:
Originally Posted by alexgeek View Post
Since there's only a few person viewing it, you'd only need one or two usernames so mysql would be pointless i guess.
This might work, haven't tested it.
login form:
Code: Select all
<form action="login.php" method="post">
<p>Username<br>
<input type="text" name="user"></p>
<p>Password:<br>
<input type="password" name="pass"></p>
<p><input type="submit" value="login"></p>
</form>
login.php:
PHP: Select all

<?php 
session_start
$username
=$_POST['user'];
$password=$_POST['pass'];
$checkuser="username"//replace username with your own.
$checkpass="password123"//replace with your own password like above

if($username == $checkuser && $password == $checkpass) {
$_SESSION['loggedin'] == $username;
} else {
echo 
"wrong username/password";
}
?>
everypage that should be protected from people not logged in should have:

PHP: Select all

<?php 
session_start
;
if (!isset(
$_SESSION['loggedin'])) {
echo 
"you aren't logged in";
exit();

?>
<!-- html here -->

That should work
Sorry if you know how to do this already.

Says there is an error on this line
PHP: Select all

$username=$_POST['user']; 

Reply With Quote