Jump to content

Why idnt it showing?


Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

?>

 

 

Link to comment
Share on other sites

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;

?>                   

           

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.