Jump to content

Recommended Posts

I am trying to get my page to redirect to another with a header. I am getting the "headers already sent by " error. I've checked for white space and researched but can't seem to find anything the pertains to my code.

 

I am thinking that I am getting the error becuase I am posting to 'self'??

 

If someone could help me with my code or even send me to a good site that deals with this.

 

<?php

        if( isset($_POST['submitLogin']))
          {
            include('login.php');
            login();
            mysql_select_db('test');

            $userID=$_POST["userID"];
            $pswd=$_POST["pswd"];

            $sql="SELECT * FROM user WHERE userID='$userID' and pswd='$pswd'";
            $result=mysql_query($sql);

            $count=mysql_num_rows($result);

            while ($r=mysql_fetch_array($result))
              {
                $exp_date=$r["exp_date"];
                $todays_date=date("Y-m-d");
              }

              if($count==1)
                {
                  if ($exp_date >= $todays_date)
                    {
                      header('Location: aboutMe.php');
                    }
                  else
                    {
                      echo "Billing is bad";
                    }
                }
              else
                {
                echo " <div id='incorrect'>Please verify the username or password.</div>

                <form method='post' action='' name='login' id='login'>
                  <div id='loginForm'>
                    <fieldset>
                      <span class='textbox'>
                        <label for='username'>Username: </label> <input type='text' name='userID' size='25' class='cells' value='$userID'>
                        <br><label for='pswd'>Password: </label> <input type='password' name='pswd' size='25'class='cells' value='$pswd'>
                        <br><label for='pswd'> </label>Remember Me:  <input type='checkbox' name='Remember' value='21'>
                        <br><label for='blank'> </label><a href='changePswd.php'>Forget Your Password?</a>
                        <br><label for='blank'> </label><input type='image' value='Login'  src='img/button_login.gif' width='64' height='25'
                            onmouseover=\"javascript:this.src='img/button_login2.gif';\" onmouseout=\"javascript:this.src='img/button_login.gif';\">

                        <input type='hidden' name='submitLogin' value='true'>

                      </span>
                    </fieldset>
                  </div>
                </form>
                ";
              }
}
        else
          {
            echo "
            <form method='post' action='' name='login' id='login'>
              <div id='loginForm'>
                <fieldset>
                  <span class='textbox'>
                    <label for='username'>Username: </label> <input type='text' name='userID' size='25' class='cells'>
                    <br><label for='pswd'>Password: </label> <input type='password' name='pswd' size='25'class='cells'>
                    <br><label for='pswd'> </label>Remember Me:  <input type='checkbox' name='Remember' value='21'>
                    <br><label for='blank'> </label><a href='changePswd.php'>Forget Your Password?</a>
                    <br><label for='blank'> </label><input type='image' value='Login' src='img/button_login.gif' width='64' height='25'
                    onmouseover=\"javascript:this.src='img/button_login2.gif';\" onmouseout=\"javascript:this.src='img/button_login.gif';\">

                    <input type='hidden' name='submitLogin' value='true'>

                  </span>
                </fieldset>
              </div>
            </form>
            ";
          }
?>

Link to comment
https://forums.phpfreaks.com/topic/193252-php-header/
Share on other sites

From my research the error has something to do with white space, so I removed it all and still getting the error.

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/i/d/2/id2294/html/singles/login.php:11) in /home/content/i/d/2/id2294/html/singles/login.php on line 49
Link to comment
https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017590
Share on other sites

I don't think that will work, I probably am missunderstanding. I am having the user log in, then the form is submitted to itself. It will either do 3 things based on if the user & pswd are valid and if the billing is up to date. Not sure how I can switch things around so that the redirect comes first.

Link to comment
https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017685
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.