papillonstudios Posted May 2, 2010 Share Posted May 2, 2010 I have created a basic login page. I have used this same login page with another small personal project that i started. But for some reason when i use it in the new application the contents of the page doesnt show, but yet it does in the other application. I have went through the syntax and there are no errors in it. no errors show when looking at the page in my browser. What other than syntax errors could be stopping the content on the page from showing. heres my code <!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>Login</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php ob_start(); session_start(); if (!isset($_POST['login'])) { //If the post hasn't been submitted, then show the forms echo '<br /><p><form method="post" action="index.php?action=login"> <p>Username:'.form_input(text,username).'</p> <p>Password:'.form_input(password,password).'</p> <input class="submit" type="submit" name="login" value="Login"><p> </form> <br> '.anchor ('index.php?action=forgot','Forgot Password?').' | '.anchor ('index.php?action=register','Register').''; } else { //secure the input $username = secure($_POST['username']); $password = secure($_POST['password']); //make sure the fields arn't empty if (!$username | !$password) { echo 'You left a field empty'; } else { //make sure the user exists $user = mysql_query("SELECT * FROM `users` WHERE username = '$username'"); if (($usez = mysql_num_rows($user)) == 0) { echo 'user doesnt exist'; } else { //Encrypt the password to check with the encrypted one currently in the database $encpass = sha1($password . SALT); //Find the user $superquery = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$encpass'"); if (mysql_num_rows($superquery) == 1) { //If the user is found, set the cookies setcookie("username", $username, $cookieTime); setcookie("password", $encpass, $cookieTime); //send the user to the home page header("Location: " . $siteurl . "index.php"); } else { echo 'Password was incorrect. Please try again.'; } } } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
foobarbaz Posted May 2, 2010 Share Posted May 2, 2010 The most common cause of nothing being displayed is an error, with error reporting off. Try turning PHP error reprorting on with the following lines: ini_set('display_errors',1); error_reporting(E_ALL); Put this at the top of your script above any HTML and it should display a clue. Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted May 2, 2010 Share Posted May 2, 2010 ob_start() AND session_start() Must be at the top of the page. James. Quote Link to comment Share on other sites More sharing options...
foobarbaz Posted May 2, 2010 Share Posted May 2, 2010 ob_start() AND session_start() Must be at the top of the page. James. Not neccesarily. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 in this case it was that and i wasnt including the config.php page that includes the functions page for form_input function that i use. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 ok its showing now but i get this error Cannot modify header information - headers already sent by (output started at *filepath*/config.php:34) in *filePath*/admin/login.php on line 77 from this code <?php setcookie("username", $username, $cookieTime); setcookie("password", $encpass, $cookieTime); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2010 Share Posted May 2, 2010 output started at *filepath*/config.php:34 What's on line 34 of config.php that is producing output? Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 heres the code foe config.php line 34 is the very end or the "?>" <?php ini_set('display_errors',1); error_reporting(E_ALL); include('functions.php'); //Database information *CENSORED* //Connect to the database $connect = mysql_connect($dbhost, $dbuser, $dbpass); if (!$connect) { die('Could Not Connect to server. Please contact the administrator. <br /><i>'. mysql_error(). '</i>'); } else { $selectdb = mysql_select_db($dbname); if (!$selectdb) { die('Could not connect to specified database.'); } } $salt = 'f9e719e10092464b1357'; //Length Of Time Cookie Lasts - 1 week default $cookieTime = time() + 7 * 86400; ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2010 Share Posted May 2, 2010 Remove any characters in the file that are after the ?> tag. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 there are none Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2010 Share Posted May 2, 2010 There ARE in the code you posted and I just copy/pasted into a file to test. Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 if you mean just blank spaces then i deleted them and no change Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 ok if your a php coder you would know that if it is at the end of the file then its something before it Quote Link to comment Share on other sites More sharing options...
papillonstudios Posted May 2, 2010 Author Share Posted May 2, 2010 fixed the error. i wasnt using this at the top of config.php ob_start(); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2010 Share Posted May 2, 2010 and no change The error message obviously changed to indicate that there was output occurring at a different point in your code. If you didn't notice that the error message was different, we cannot help you. You already have an ob_start(); in the code you posted. It is after you have output something on the page, so it is not doing any good, but taking up extra processing time and memory. Adding a second ob_start(), while it does hide the cause of the error, adds even more overhead on the page (you have two nested levels of output buffering now.) It is always best to find and fix problems, rather than to hide them. 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.