Kamsee Posted July 5, 2007 Share Posted July 5, 2007 <?php // Connect to the database server $dbcnx = @mysql_connect("localhost", "steve", "555555"); if (!$dbcnx) { echo( "<p>Unable to connect to the " . "database server at this time.</p>"); exit(); } // Select the destiny database if (! @mysql_select_db("campus") ) { echo( "<p>Unable to locate the " . "database at this time.</p>" ); exit(); } //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location:index.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die("<font size='2' face='Verdana, Arial, Helvetica, sans-serif'><h3>Sorry!</h3> You did not fill in a required field. Click the <a href='javascript:history.back(1)'><img src='../images/back.gif' width='12' height='16' border=0 valign=bottom> Back </a> button to try again."); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die("<font size='2' face='Verdana, Arial, Helvetica, sans-serif'><h3>Sorry!</h3> The username supplied does not exist in our database. Click the <a href='javascript:history.back(1)'><img src='../images/back.gif' width='12' height='16' border=0 valign=bottom> Back </a> button to try again."); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $_POST['password'] = stripslashes($_POST['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['password'] !=$info['pass']) { die("<font size='2' face='Verdana, Arial, Helvetica, sans-serif'><h3>Sorry!</h3> The password supplied is wrong. Click the <a href='javascript:history.back(1)'><img src='../images/back.gif' width='12' height='16' border=0 valign=bottom> Back </a> button to try again."); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location:index.php"); } } } else { // if they are not logged in ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title> Login Page</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="file:///C|/wamp/www/stivi/align.css" rel="stylesheet" type="text/css"> <meta name="keywords" content="Website, Web Design, E-cards, Cards, Photo Album, Research, E-research, E-mail, Mail, Newsmail, SMS, Kenya, Professional, Best, Excellent, Web-Marketing, E-marketing, college"> <meta name="description" content="Come to Destiny, the best place for web-based products. At Destiny you will find items that will change your Destiny."> <meta name="keywords" content="Destiny, Success"> <style type="text/css"> <!-- .style3 { font-size: 24px; font-weight: bold; color: #006699; } .style7 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> </head> <body leftmargin="2" topmargin="1" bgcolor="#F5F5FA"> <table width="775" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#4A9500"> <tr> <td valign="bottom"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td background="file:///C|/wamp/www/stivi/images/blu-ln.gif"><img src="file:///C|/wamp/www/stivi/images/blu-ln.gif" width="10" height="1"></td> </tr> <tr> <td bgcolor="#E2E2EF"><div align="center"><span class="style3">Fdcs :: Login System </span></div></td> </tr> <tr> <td> </td> </tr> <tr> <td height="20" valign="middle"> <div align="center"></div></td> </tr> <tr> <td valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="20%" valign="top" bgcolor="#F5F5FA"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="#0099FF"> <div align="center"><strong><font color="#0099FF" size="2">.</font></strong></div></td> </tr> <tr> <td valign="top"> </td> </tr> </table></td> <td width="2%" valign="top" bgcolor="#FBFBFD"> </td> <td width="56%" valign="top" bgcolor="#FBFBFD"> <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E2E2EF"> <tr> <td><table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#FBFBFD"> <tr> <td bgcolor="#E2E2EF"><font color='#000099' size='2' face='Verdana, Arial, Helvetica, sans-serif'><strong>Login Area </strong></font></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="center"><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>The only means to reach the members area. Login here</font></div></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="center"><font color='#84BE2C'size='4'><strong>*****************</strong></font></div></td> </tr> <tr> <td><div align="center"><font color='#84BE2C'size='4'></font></div></td> </tr> <tr> <td><font size="4" face="Verdana, Arial, Helvetica, sans-serif"> </font></td> </tr> <tr> <td> <p> </p></td> </tr> <tr> <td><div align="center"> <form action="<?php echo $_SERVER['file:///C|/wamp/www/stivi/ogesite/PHP_SELF']?>" method="post"> <table border="0"> <tr> <td colspan=2><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Username:</font></td> <td> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <input type="text" name="username" maxlength="40"> </font></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Password:</font></td> <td> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <input type="password" name="pass" maxlength="50"> </font></td> </tr> <tr> <td colspan="2" align="right"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <input type="submit" name="submit" value="Login"> </font></td> </tr> </table> </form> <?php } ?> </div></td> </tr> <tr> <td><div align="center"><font color='#84BE2C'size='4'></font></div></td> </tr> <tr> <td><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Not a member? <a href="file:///C|/wamp/www/stivi/ogesite/register.php">Register Here</a></font></div></td> </tr> <tr> <td> </td> </tr> <tr> <td><div align="center"><font color='#84BE2C'size='4'><strong>*****************</strong></font></div></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table></td> </tr> </table></td> <td width="2%" valign="top" bgcolor="#FBFBFD"> </td> <td width="20%" valign="top" bgcolor="#F5F5FA"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="#0099FF"> <div align="center"><strong><font color="#0099FF" size="2">.</font></strong></div></td> </tr> <tr> <td valign="top"> </td> </tr> </table></td> </tr> </table></td> </tr> <tr> <td> </td> </tr> <tr> <td bgcolor="#E2E2EF"> <div align="center" class="style7"><font size="2">By Great Designs LTD </font></div></td> </tr> <tr> <td background="file:///C|/wamp/www/stivi/images/blu-ln.gif"><img src="file:///C|/wamp/www/stivi/images/blu-ln.gif" width="10" height="1"></td> </tr> </table></td> </tr> </table> </body> </html> Could anyone please help me out The code above is working well interms of Registering but when it comes to Logging in There is a problem in that it cant display the members Area Any suggestions are highly welcomed. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 5, 2007 Share Posted July 5, 2007 Surrounding code with CODE tags will get you a quicker response. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.