hey

i have a login form that looks like this:

<?php
if(!isset($_POST['submit'])) {
  //form here
}
else {
  //code here
}
?>

now in the code i check for errors in the fields like usuall. If an error is found, like the text in the password field is to short, then it need to be redirected to the login page with page.php?error=something.

but i cant use header(location: page.php?error=something) because headers already send by.
Also i dont want the code in a seperated file for some reasons.
And i want the error be displayed at the login form.

how can i do this? please help me.

    hmm i think thats not what i meant, i explain a little different:

    <?php 
    if(!isset($_POST['submit'])) { 
      //form here 
    } 
    else { 
      if ( strlen($_POST['password']) <= 4) {
        header("location: loginpage.php?error=anerror");
      }
    } 
    ?> 

    like that it need to become. Only i cant use header() because headers are already send by.

    i want to know another way to do this..
    and i dont want the users to hit a back button or retry button.

    so not like this:

    <?php 
    if(!isset($_POST['submit'])) { 
      //form here 
    } 
    else { 
      if ( strlen($_POST['password']) <= 4) {
        echo "password is to short<br><a href='login.php'>back</a>";
      }
      else {
        //the rest of the code..
      }
    } 
    ?> 

      The headers do not have to be already passed by. Put this statement before the <HEAD> tag and you should be able to echo into this. If that is not possible I would look for a javascript code that can do this.

      I found this on on the net it might work.

      JavaScript Redirects

      <script language=javascript>
          setTimeout("location.href='[some-url]'", [time]);
          </script>

      Replace [time] with milliseconds. This will pause the browser for the specified number of seconds. Replace [some-url] with the target URL you want to redirect. For example,

       setTimeout("location.href='http://www.yahoo.com'", 5000); 

        hey

        much thanx you trying to help me out Aybabtu.
        but the headers are always send by. because i have my current page always included in the index.

        like this:

        index.php?id=home
        index.php?id=login
        etc.

        so i always have the code before from the index.php even if i put the code on top of my home.php.

        also i actually dont wanna use any javascript in my webpage :glare:

        greets

          Only i cant use header() because headers are already send by.

          Ensure that you have no output before you use header(). This is includes whitespace.

          Alternatively you can use output buffering, but I think that just avoiding output before header() is usually better.

            what you mean with Alternatively you can use output buffering laserlight?
            or how do i use that?

              Read the PHP Manual on Output Control Functions.

              Still, have you checked for say, a blank line at the top of your script? Or even some HTML/XHTML that should not be output so early?

                yeah i always have output before, like i said i designed the page with a code that include all pages on a certain place in my index.php so i dont have to work with frames.

                so all my pages come with index.php?id=thepagename

                so if i include my login.php in my index.php that means that theres always output before.

                  Then you need to re-structure your code a little.

                  Logically, you dont need to output anything until you have processed the login form. What you can do is shift the include to the portion of code after you have verified the user login.

                    why wouldnt you advice me to enable the outpu buffering? (because i rather do that then reconstruct my site)
                    that make my site slower or something?

                      I am of the opinion that large scale output buffering is like the use of goto - to be used only in special cases, and otherwise avoided at all costs.

                      You probably dont have the re-construct your entire site, only the page with the login form.

                        If you put ob_start(); at the very start of your script, and ob_end_flush(); at the very end, it shouldn't tell you headers have already been sent.

                          Write a Reply...