Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 August 1st, 2008, 11:18 AM
Registered User
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP Login Page errors - Please Solve and Help

Following are the errors that I get from the page that I have made for
Login and below I have attached the login.php file. I understand that
it has to do something with sessions but then I connot figure out how
to solve the problem. Your help will be appreciated. Please let me
know if you want me to post the other included files also.

Warning: session_start(): Cannot send session cookie - headers already
sent by (output started at C:\apache2triad\htdocs\paramarsh\regsys\lib
\common.php:35) in C:\apache2triad\htdocs\paramarsh\regsys\public_fil es
\login.php on line 8 Warning: session_start(): Cannot send session
cache limiter - headers already sent (output started at C:\apache2triad
\htdocs\paramarsh\regsys\lib\common.php:35) in C:\apache2triad\htdocs
\paramarsh\regsys\public_files\login.php on line 8 Warning: Cannot
modify header information - headers already sent by (output started at
C:\apache2triad\htdocs\paramarsh\regsys\lib\common .php:35) in C:
\apache2triad\htdocs\paramarsh\regsys\public_files \login.php on line
9


--------------


login.php


<?php
// include shared code
include '../lib/common.php';
include '../lib/db.php';
include '../lib/user.php';


// start or continue the session
session_start();
header('Cache-control: private');


// perform login logic if login is set
if (isset($_GET['login']))
{
        if (isset($_POST['username']) && isset($_POST['password']))
        {
                // retrieve user record
                $user = (User::validateUsername($_POST['username'])) ?
                User::getByUsername($_POST['username']) : new User();
                        if ($user->userId && $user->password == sha1($_POST['password']))
                        {
                                // everything checks out so store values in session to track the
                                // user and redirect to main page
                                $_SESSION['access'] = TRUE;
                                $_SESSION['userId'] = $user-> userId;
                                $_SESSION['username'] = $user-> username;
                                header('Location: main.php');
                        }
                        else
                        {
                                // invalid user and/or password
                                $_SESSION['access'] = FALSE;
                                $_SESSION['username'] = null;
                                header('Location: 401.php');
                        }
        }
        // missing credentials
        else
        {
                $_SESSION['access'] = FALSE;
                $_SESSION['username'] = null;
                header('Location: 401.php');
        }
        exit();



}


// perform logout logic if logout is set
// (clearing the session data effectively logsout the user)
else if (isset($_GET['logout']))
{
        if (isset($_COOKIE[session_name()]))
        {
                setcookie(session_name(), '', time() - 42000, '/');
        }

        $_SESSION = array();
        session_unset();
        session_destroy();



}


// generate login form
//ob_start();
?>

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>?
login" method="post">
<table>
<tr>
<td><label for="username"> Username </label></td>
<td><input type="text" name="username" id="username"/></td>
</tr>
<tr>
<td><label for="password"> Password </label></td>
<td><input type="password" name="password" id="password"/></td>
</tr><tr>
<td></td>
<td><input type="submit" value="Log In"/ ></td>
</tr>
</table>
</form>
//<?php
$GLOBALS['TEMPLATE']['content'] = ob_get_clean();
//display the page
include '../templates/template-page.php';
?>


--------



 
Old August 4th, 2008, 05:25 AM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to v08i
Default

Hi,

This error is generated when you output anything to browser prior to session_start().
Check all your statements before session_start() and make sure that you dont have any tab, whitespace,echo or print statement before session_start().
This error will go away if you put session_start in the very first line.


--
Vijay Joshi
http://vijayjoshi.org

 
Old October 5th, 2008, 07:14 PM
Authorized User
 
Join Date: Oct 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

look for empty spaces in paramarsh\regsys\lib\common.php:35 and login.php before <?php tag and remove if you found one, check for any echo or any thing which can do a print to response stream

thanks

http://FindaJobSearch.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a login page in PHP bhavna General .NET 0 February 16th, 2007 07:32 AM
php errors p2ptolu Beginning PHP 2 May 16th, 2005 05:19 AM
Newbie Help. Login to unique login page per user Kainan Classic ASP Professional 10 May 3rd, 2005 07:47 AM
Php Installation errors kuehhc Beginning PHP 3 December 13th, 2004 12:37 PM
PHP login/upload page narayana69m Beginning PHP 1 March 28th, 2004 05:46 PM





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