iGuest 3 Report post Posted December 31, 2004 can someone help me with a php&mysql password code for my web page??? An example should be perfect... Share this post Link to post Share on other sites
iGuest 3 Report post Posted January 1, 2005 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
iGuest 3 Report post Posted January 1, 2005 I'll try to use this code. If I have problems I'll contact you again! Thank you for your attention! Happy New Year! Share this post Link to post Share on other sites
iGuest 3 Report post Posted January 2, 2005 glad you got ithappy new year too.. Share this post Link to post Share on other sites