Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 204
0 Users 1 Guests Online

Simple Session Login

Okay this is really basic if you ask me...heh..

Okay just make a file named index.php or what ever you would like really.

In it type something like:

Code

<?php
session_start(); //allow sessions
$username = "user"; //username variable change with the username you wish to use
$password = "pass"; //password variable, change this to what you wish it to be
if(!isset($_SESSION[user]) && !isset($_SESSION[pass]) && !$_POST[login]){ //checks login and that the form was not submitted
?>
<form method="post">
<b>Username</b>:<br />
<input type="text" name="user" size="15"><Br />
<b>Password</b>:<br />
<input type="password" name="pass" size="15"><br />
<input type="submit" name="login" value="Login"><br />
</form><!-- this is the form area and such things-->
<?
}elseif(!isset($_SESSION[user]) && !isset($_SESSION[pass]) && $_POST[login]){ //check if form was submitted and the sessions are not set
if($_POST[user] !== $username || $_POST[pass] !== $password){ //check if user or password were wrong
echo "<b>Error</b>: Invalid Username/Password"; //the error
}else{ //or go on
$u = md5(sha1($_POST[user])); //secure username
$p = md5(sha1($_POST[pass])); //secure password
$_SESSION[user] = $u; //set session
$_SESSION[pass] = $p; //set session
echo "You Have Been Logged In Please Wait While You Are Redirected."; //success and redirect
} //end post checking
}elseif(isset($_SESSION[user]) && isset($_SESSION[pass])){ //sessions are set check
?>
<!--this is where the hidden content goes-->
<h4>Welcome</h4>
<p>Hidden Content Here</p>
<?
} //end the session check and the post check thing...
?>


That should be it and yes this does work i have tried it on my localhost.
ShadowMage
Author:
Views:
1506
Rating:
Posted on Friday 1st June 2007 at 05:56 PM
ShadowMage
ShadowMage
i write my scripts down on paper during school hours and whatnot then when i get home i type it up and debug.
Posted on Friday 9th March 2007 at 05:58 PM
sarye
sarye
Nice Shadow! I couldn't do that for cheese esspecially in school with people hanging over my shoulder asking What are you doing?.lolz

~Nae
Posted on Wednesday 7th March 2007 at 08:26 PM
ShadowMage
ShadowMage
heh :) did this one in 6th period during movie >.> 'Course i was still paying attention and such :P