carleihar Posted January 16, 2010 Share Posted January 16, 2010 <?php # Script 16.8 - login.php // This is the login page for the site. require_once ('../includes/config.inc.php'); require_once ('../../mysqli_connect.php'); include ('../includes/header.html'); if (isset($_POST['submitted'])) { require_once (MYSQL); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } if ($e && $p) { // If everything's OK. // Query the database: $q = "SELECT username, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $result = mysql_query($q); $row = mysql_fetch_array($result); $username = $row['username']; if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: setcookie("user", "$username", time()+3600); mysqli_free_result($r); mysqli_close($dbc); ob_end_clean(); // Delete the buffer. ?> <script language="javascript"> window.location = "http://www.liveequian.com/htdocs/pages/login_main.php"; </script> <? //header("location: login_main.php"); exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <?php // Include the HTML footer. include ('../includes/footer.html'); ?> This is driving me crazy... when it reaches "login_main.php" it does not recognize the cookie: <?php //template include ('../includes/header.html'); echo '<h1>Login Main</h1>'; require_once ('../../mysqli_connect.php'); echo "sdfj"; echo $_COOKIE["user"]; if (isset($_COOKIE["user"])){ echo "Welcome " . $_COOKIE["user"] . "!<br />"; } else{ echo "Welcome guest!<br />"; } echo '<br>'; echo 'page goes here'; include ('../includes/footer.html'); ?> It reads, "Welcome Guest!" Any help? In case you need them: Header.php: <?php # Script 16.1 - header.html // This page begins the HTML header for the site. // Start output buffering: ob_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="../includes/css/main.css" rel="stylesheet" type="text/css" /> </head> <body> <center><div id="mainshell"> <br /><br /> <div id='maincontent'> Footer: <?php ?> </div> <!--end maincontent div--> </div> <!--end mainshell div--> </body> </html> <?php // Flush the buffered output. ob_end_flush(); ?> Any help? Link to comment https://forums.phpfreaks.com/topic/188649-cookie-help/ Share on other sites More sharing options...
trq Posted January 16, 2010 Share Posted January 16, 2010 You are mixing two different mysql extensions together in various places. Make sure error reporting is set to E_ALL and display errors are on then execute your code again. I would be surprised if there aren't issues. Link to comment https://forums.phpfreaks.com/topic/188649-cookie-help/#findComment-995931 Share on other sites More sharing options...
carleihar Posted January 16, 2010 Author Share Posted January 16, 2010 I'm sorry but do you think you could explain a little more? Maybe point out where there are two different extensions? Link to comment https://forums.phpfreaks.com/topic/188649-cookie-help/#findComment-996121 Share on other sites More sharing options...
Buddski Posted January 16, 2010 Share Posted January 16, 2010 You are executing the same query twice. Once with mysqli and again with mysql $q = "SELECT username, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $result = mysql_query($q); $row = mysql_fetch_array($result); $username = $row['username']; if (@mysqli_num_rows($r) == 1) { // A match was made. Its kind of pointless doing that... Link to comment https://forums.phpfreaks.com/topic/188649-cookie-help/#findComment-996123 Share on other sites More sharing options...
carleihar Posted January 16, 2010 Author Share Posted January 16, 2010 <?php # Script 16.8 - login.php // This is the login page for the site. require_once ('../includes/config.inc.php'); require_once ('../../mysqli_connect.php'); include ('../includes/header.html'); if (isset($_POST['submitted'])) { require_once (MYSQL); // Validate the email address: if (!empty($_POST['email'])) { $e = mysqli_real_escape_string ($dbc, $_POST['email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address!</p>'; } // Validate the password: if (!empty($_POST['pass'])) { $p = mysqli_real_escape_string ($dbc, $_POST['pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password!</p>'; } if ($e && $p) { // If everything's OK. // Query the database: $q = "SELECT username, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); //$row = mysql_fetch_array($r); //$username = $row['username']; if (@mysqli_num_rows($r) == 1) { // A match was made. // Register the values & redirect: setcookie("email", $e, time()+3600); //$_SESSION = mysqli_fetch_array ($r, MYSQLI_ASSOC); ?> <script language="javascript"> window.location = "http://www.liveequian.com/htdocs/pages/login_main.php"; </script> <? //header("location: login_main.php"); mysqli_free_result($r); mysqli_close($dbc); ob_end_clean(); // Delete the buffer. exit(); // Quit the script. } else { // No match was made. echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>'; } } else { // If everything wasn't OK. echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } // End of SUBMIT conditional. ?> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email Address:</b> <input type="text" name="email" size="20" maxlength="40" /></p> <p><b>Password:</b> <input type="password" name="pass" size="20" maxlength="20" /></p> <div align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <?php // Include the HTML footer. include ('../includes/footer.html'); ?> I've edited it a little but its still not working. Now it's not going into login_main.php at all, just staying blank at login.php. It's driving me crazy! Any help? Link to comment https://forums.phpfreaks.com/topic/188649-cookie-help/#findComment-996133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.