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 June 3rd, 2004, 04:14 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Header error

i am trying to use the redirect method header("location: links.php");
but some how or rather i always get the error message
Cannot modify header information

the code is working fine with the statements but once i put in the statements it just prompts error.

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\sam\Organizer\login.php:12) in c:\inetpub\wwwroot\sam\Organizer\login.php on line 44

<?php
   include("dblib.inc");
   include("clublib.inc");

    $message="";

    $actionflag = $_POST['actionflag'];
    $login = $_POST['login'];
    $password = $_POST['password'];

// +++++++++++ Debug ++++++++++
    print "actionflag : " .$actionflag. "<br />\n";
    print "login : " .$login. "<br />\n";
    print "password : " .$password. "<br />\n";
    print "session_name : ". session_name(). "<br />\n";
    print "session_id :" .session_id(). "<br />\n";
// +++++++++++ Debug ++++++++++

    if ( isset( $actionflag ) && $actionflag == "login" )
        {
        if ( empty( $login ) || empty( $password ) )
           $message .= "you must fill in all fields<br>\n";

       if ( ! ( $row_array = checkPass( $login, $password ) ) )
           $message .= "Incorrect password try again<br>\n";

       if ( $message == "" ) // we found no errors
           {
// +++++++++++ Debug ++++++++++
            print "ID : ".$row_array[id]."<br />\n";
            print "row_array[login] : ".$row_array[login]."<br />\n";
            print "row_array[password] : ".$row_array[password]."<br />\n";
// +++++++++++ Debug ++++++++++

           cleanMemberSession( $row_array[id], $row_array[login], $row_array[password] );

// +++++++++++ Debug ++++++++++
               print "sessionID : ".$session[id]."<br />\n";
               print "sessionLogin : ".$session[login]."<br />\n";
               print "sessionPassword : ".$session[password]."<br />\n";
               print "sessionLogged_in : ".$session[logged_in]."<br />\n";
// +++++++++++ Debug ++++++++++

           header("Location: membersmenu.php");
           }
       }
   ?>

   <html>
   <head>
   <title>Login</title>
   </head>

   <body>

   <?php
   include("publicnav.inc");
   ?>

   <h1>Login</h1>

   <?php
   if ( $message != "" )
       {
       print "<p><b>$message</b></P>";
       }
   ?>

   <p>
   <form Method="post" action="<?php print $_SERVER['PHP_SELF'];?>">
   <input type="hidden" name="actionflag" value="login">
   <input type="hidden" name="<?php print session_name() ?>"
          value="<?php print session_id() ?>">
   </p><p>
   Login: <br>
   <input type="text" name="login"
          value="<?php print $login ?>">
   </p><p>
   Password: <br>
   <input type="password" name="password" value="">
   </p><p>
   <input type="submit" value="update">
   </form>

   </body>
   </html>
 
Old June 3rd, 2004, 08:40 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You cannot use header() when you have already outputted (that's a fancy word) text. You have been using print. Please see the FAQ on redirects (home/php/php faqs).

Snib

<><
 
Old June 3rd, 2004, 09:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Snib,

thanks for the reply. Do u mean that there should not be any output in the page at all when using header? Or can it works in block?
meaning
<%php %> - 1 block
<%php %> - another block

i was not able to find any faq u mention.
can you drop a link here? thanks
i only manage this --> http://sg.php.net/manual/en/function.header.php
 
Old June 3rd, 2004, 09:12 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The FAQ is here: http://p2p.wrox.com/topic.asp?TOPIC_ID=11882

Snib

<><
 
Old June 3rd, 2004, 09:20 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Snib,

thank u so much.
Now i understand. :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Header Tags & Controls Come back as Error Ian Btn VS.NET 2002/2003 1 November 13th, 2008 10:35 AM
Header Error jeffrowe BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 October 7th, 2006 09:45 AM
header footer zaman1111 JSP Basics 0 July 28th, 2005 05:00 PM
Report Header JohnBoyUK BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 October 28th, 2004 07:10 AM
ODBC ERROR IN ARCHIVE /include/header.asp, line 11 jonnyl Forum and Wrox.com Feedback 1 June 11th, 2003 09:05 AM





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