Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2006, 02:15 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default LOGIN

I am unable to get my login in script as i am recieving error messages like this in the broswer

Warning: Cannot modify header information - headers already sent by (output started at c:\apache\cgi-bin\login.php:7) in c:\apache\cgi-bin\login.php on line 48

Warning: Cannot modify header information - headers already sent by (output started at c:\apache\cgi-bin\login.php:7) in c:\apache\cgi-bin\login.php on line 49

Warning: Cannot modify header information - headers already sent by (output started at c:\apache\cgi-bin\login.php:7) in c:\apache\cgi-bin\login.php on line 62

I have no idea why these errors are being reported

this is my code

#!c:/php/php.exe
<html>
<head>
<title>login</title>
</head>
<body>
<?php #Script9.1 - login.php2
// send nothing to the web browser prior to the set cookies line


// check if the form been submitted
if(isset($_POST['submitted']))
{
    //register the user in a database
    require_once ('mysql_connect.php'); // connect to the database

    $errors = array(); //Initialise error array

    //check for an email address.
    if(empty($_POST['email']))
    {
        $errors[] = 'You forgot to enter your email address';
    }
    else
    {
        $e = escape_data($_POST['email']);
    }

    //check for an password.
    if(empty($_POST['password']))
    {
        $errors[] = 'You forgot to enter your password';
    }
    else
    {
        $p = escape_data($_POST['password']);
    }

    if(empty($errors)) // if everything is okay
    {
        /* Retrieve the user_id and first name for that email/password combination.*/
        $query = "SELECT personID, first_name FROM test WHERE email='$e' AND password=SHA('$p')";
        $result = @mysql_query ($query); // Run the query.
        $row = mysql_fetch_array ($result, MYSQL_NUM); //return a record if applicable

        if ($row) // a record was pulled from the database
        {
            setcookie ('personID', $row[0]);//
//setthecookies and redirect
            setcookie ('first_name', $row[1]);

            //rediret the user to the the loggedin.php page
            //start defining the url
            $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
            if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') )
            {
                $url = substr ($url, 0, -1); // chop of slash.
            }

            // ADD THE PAGE
            $url .='C:\Apache\cgi-bin\loggedin.php';

            header("Location: $url");
            exit(); // quit the script


        }
        else // no records matched the query
        {
            $errors[] = 'The email address and password entered do not match those on file';
            // public message

            $errors[] = mysql_error() . '<br /><br />Query: ' . $query; // debugging message
        }

    }// end of if (empty($errors)) IF

    mysql_close(); //close the database connection

    }
    else // form has not been submitted
    {
            $errors = NULL;

    } // END of main submit conditional

    // begin the page now
    $page_title = 'login';
    include('C:\Apache\htdocs\header2.html');

    if (!empty($errors)) //print any error message
    {
        echo '<h1 id="mainhead">ERROR!!</h1> <p class = "error"> the following error(s) occured:<br />';
        foreach ($errors as $msg)
        {//print each error
            echo " - $msg<br />\n";
        }

        echo '</p><p> Please try again. <p/>';
    }


// create the form
?>
<h2>Login</h2>
<form action="login.php" method="post">
<p>Email Address: <input type="text" name="email" size="20" maxlength="40"/></p>
<p>Password: <input type="password" name="password" size="20" maxlength="20"/></p>
<p><input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include('C:\Apache\htdocs\footer.html');
?>
</body>
</html>


 
Old March 28th, 2006, 11:59 AM
Registered User
 
Join Date: May 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Your problem is with the beginning of the page:

Quote:
quote:#!c:/php/php.exe
<html>
<head>
<title>login</title>
</head>
<body>
As far as your page is concerned you have already sent headers to the browser. You need to put it after your header or cookie function (lines 48/49 and 62), towards the bottom of the page - after all the php code. You are basically sending headers on top of headers and the parser/browsers don't like this.

You also don't need the shebang line at the top of your script.

I hope this helps
 
Old March 31st, 2006, 12:37 AM
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You must have declear header on top of the page or before
the Html code,and never leave any blank line before the hader
Decleration.Hader Never Work After Html Tag.
I think U Understand Your Problem

Best Regards
Shekhar Srivastava









Similar Threads
Thread Thread Starter Forum Replies Last Post
login script: user can't hit "return" for login dmerrill Java Basics 13 July 14th, 2006 07:25 PM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.