Jump to content
xisto Community
Sign in to follow this  
iGuest

script code

Recommended Posts

Hi,Here i have given code example...///// Table creationCREATE TABLE users ( user_id int(10) unsigned NOT NULL auto_increment, username varchar(20) NOT NULL default '', password varchar(20) NOT NULL default '', PRIMARY KEY (user_id)) TYPE=MyISAM;///Authentication Code--> auth.php<?// Login & Session example by sde// auth.php// start sessionsession_start();// convert username and password from _POST or _SESSIONif($_POST["username"]){ $username=$_POST["username"]; $password=$_POST["password"]; }elseif($_SESSION["username"]){ $username=$_SESSION["username"]; $password=$_SESSION["password"];}// start and register session variablessession_register("username");session_register("password");// connect to databaseinclude("connect.php");// query for a user/pass match$result=mysql_query("select * from users where username='" . $username . "' and password='" . $password . "'");// retrieve number of rows resulted$num=mysql_num_rows($result);// print login form and exit if failed.if($num < 1){ session_destroy(); echo "You are not authenticated. Please login.<br><br> <form method=POST action=index.php> username: <input type=text name="username"> password: <input type=password name="password"> <input type=submit> </form>"; exit;}?> /////// DB connect code ----> connect.php<?// Login & Session example by sde// connect.php// replace with your db info$hostname="localhost";$mysql_login="root";$mysql_password="";$database="test";if (!($db = mysql_connect("$hostname", "$mysql_login" , "$mysql_password"))){ print("Can't connect to mysql."); }else{ if (!(mysql_select_db("$database",$db))) { print("Can't connect to db."); }}?> /////// Logout Script -----> logout.php<?// Login & Session example by sde// logout.php// you must start session before destroying itsession_start();session_destroy();echo "You have been successfully logged out.<br><br>You will now be returned to the login page.<META HTTP-EQUIV="refresh" content="2; URL=index.php"> ";?> Have a Nice Day..... :wink: Bye ...Sam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.