Jump to content

plz help me session header error


LOSTBOY

Recommended Posts

hi experts ,

   

        am an php beginner when try to redirect using header() it throws error as below what can i do for this ..

 

Warning: Cannot modify header information - headers already sent by (output started at c:\wamp\www\rapid\user\login.php:3) in c:\wamp\www\rapid\user\login.php on line 9

 

 

my code

<?php
if(isset($_POST['submit'])): ?>
  <?php
    include_once("clsuser.php");

          $objuser = new user;
  $objuser->validateuser($_POST['uname'], $_POST['pass']);
  header('Location: http://localhost/rapid/main/campaign.php');
  ?>
<?php else: ?>

//HTML CODE HERE

Plz help me ASAP

Link to comment
https://forums.phpfreaks.com/topic/88901-plz-help-me-session-header-error/
Share on other sites

Your code is using excessive and unnecessary opening and closing php tags. Between the first closing php tag - ?> and the next opening php tag - <?php you have some white-space in your file. This is output to the browser and prevents headers from being sent.

 

When you have a continuous block of php code, put one opening php tag - <?php at the beginning of it and one closing php tag - ?> at the end of it. Don't use three sets of opening and closing php tags like in the posted code.

When you are using header you can not send an output to the browser because you will get the error which you are getting.

 

So you can't use echo or print. Neither you can send html output. It need's to be clean PHP code, without output and on the end header.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.