Page redirection doesn't work using header function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • warezguy05
    New Member
    • Oct 2006
    • 14

    #1

    Page redirection doesn't work using header function

    Hi

    I'd like to forward users to a 'thank-you' page after they've submitted a form.

    I used this code and it worked perfectly till yesterday;

    header("Locatio n: http://www.ernestoow.c om/mudlands/bedankt.html");

    Right now..after submitting the data, the form refreshes and is empty again..although the submitted data is inserted into the database and a confirmation email is sent to the submitter.

    What can be the problem?


    full code;

    [php]

    <?



    if (isset($_POST['Submit']))
    {
    $voornaam = $_POST['voornaam'];
    $achternaam = $_POST['achternaam'];
    $adres = $_POST['adres'];
    $postcode = $_POST['postcode'];
    $plaats = $_POST['plaats'];
    $telnummer = $_POST['telnummer'];
    $dagen = $_POST['dagen'];
    $email = $_POST['email'];

    if(!$_POST['voornaam'] || !$_POST['achternaam'] || !$_POST['adres'] || !$_POST['postcode'] || !$_POST['plaats'] || !$_POST['telnummer'] || !$_POST['dagen'] || !$_POST['email'])


    {
    die(

    '<html>
    <title>mudlands </title>
    <link href="styleshee t.css" type="text/css" rel="stylesheet ">
    <body>

    <div id="header">

    <img src="mudlandshe ader.jpg" border="0">

    </div>

    <div id="menu">

    <b>Vrijwilliger </b>
    <br>
    &nbsp; &nbsp; <a href="inschrijv en.php">Inschri jven</a>
    <p>
    <b>Coordinato r</b>
    <br>
    &nbsp; &nbsp; <a href="vrijwilli gers.php">Insch rijvingen</a>
    <br>
    &nbsp; &nbsp; <a href="search.ph p">Zoeken</a>

    </div>

    <div id="back">
    </div>

    <div id="main">
    <p>
    Je hebt niet alle velden ingevuld!
    </div>

    </body>
    </html>'

    );
    }


    $sql = "INSERT INTO VRIJWILLIGER(VO ORNAAM, ACHTERNAAM, ADRES, POSTCODE, PLAATS, TELNUMMER, EMAIL) VALUES ('$voornaam', '$achternaam', '$adres', '$postcode', '$plaats', '$telnummer', '$email')";

    mysql_query($sq l) or die ("SQL1: ".mysql_error() );

    $query = "SELECT VRIJWILLIGER_ID , TELNUMMER FROM VRIJWILLIGER
    where TELNUMMER = $telnummer";

    $result = mysql_query($qu ery)
    or die("Er is een fout opgetreden");


    $id=mysql_resul t($result,"VRIJ WILLIGER_ID");


    $datum_inschrij ving = date("j F, Y, G:i");


    $sql2 = "INSERT INTO INSCHRIJVING(VR IJWILLIGER_ID, DAGEN, DATUM_INSCHRIJV ING) VALUES ('$id', '$dagen', '$datum_inschri jving')";

    $result2 = mysql_query($sq l2)
    or die("Er is weer een fout opgetreden");


    // Email versturen na aanmelding. $email is al bekend
    // Subject
    $subject = "Aanmelding Mudlands Festival";
    // Bericht
    $message = "blablabla" ;
    mail($email, $subject, $message, "From: info@ernestoow. com");

    header("Locatio n: http://www.ernestoow.c om/mudlands/bedankt.html");


    }

    ?>

    <html>
    <title>mudlands </title>
    <link href="styleshee t.css" type="text/css" rel="stylesheet ">
    <body>

    <div id="header">

    <img src="mudlandshe ader.jpg" border="0">

    </div>

    <div id="menu">

    <b>Vrijwilliger </b>
    <br>
    &nbsp; &nbsp; <a href="inschrijv en.php">Inschri jven</a>
    <p>
    <b>Coordinato r</b>
    <br>
    &nbsp; &nbsp; <a href="vrijwilli gers.php">Insch rijvingen</a>
    <br>
    &nbsp; &nbsp; <a href="search.ph p">Zoeken</a>

    </div>

    <div id="back">
    </div>

    <div id="main">
    Inschrijven


    <form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
    <p>

    <table border="0" cellspacing="2" cellpadding="2" >
    <tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Voornaam:
    </font>
    </td>
    <td>
    <input name="voornaam" type="text" id="voornaam" maxlength="30" />
    </td>
    </tr>
    <tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Achternaam:
    </font>
    </td>
    <td>
    <input name="achternaa m" type="text" id="achternaam " maxlength="30" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Adres:
    </font>
    </td>
    <td>
    <input name="adres" type="text" id="adres" size="40" maxlength="50" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Postcode:
    </font>
    </td>
    <td>
    <input name="postcode" type="text" size="9" maxlength="7" id="postcode" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Plaats:
    </font>
    </td>
    <td>
    <input name="plaats" type="text" id="plaats" maxlength="40" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Mobiel nummer:
    </font>
    </td>
    <td>
    <input name="telnummer " type="text" value="06" size="13" maxlength="10" id="telnummer" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    E-mail:
    </font>
    </td>
    <td>
    <input name="email" type="text" size="35" maxlength="30" id="email" />
    </td>
    </tr>
    <td width="120">
    <font face="Arial, Helvetica, sans-serif" size="2">
    Beschikbaarheid :
    </font>
    <br>
    <font face="Arial, Helvetica, sans-serif" size="1">
    (dagen)
    </font>
    </td>
    <td>
    <select name="dagen" id="dagen" size="2">
    <option value="2">2</option>
    <option value="5">5</option>
    </td>
    </tr>
    </table>
    <p>
    <input type="submit" name="Submit" value="Registre er" />
    <input name="Clear" type="reset" id="Clear" value="Wissen" />
    </p>

    </form>
    </div>

    </body>
    </html>
    [/php]
  • tomongous
    New Member
    • Oct 2006
    • 1

    #2
    Originally posted by warezguy05
    Hi

    I'd like to forward users to a 'thank-you' page after they've submitted a form.

    I used this code and it worked perfectly till yesterday;

    header("Locatio n: http://www.ernestoow.c om/mudlands/bedankt.html");

    Right now..after submitting the data, the form refreshes and is empty again..although the submitted data is inserted into the database and a confirmation email is sent to the submitter.

    What can be the problem?
    ...
    Warezguy,
    I just tried your script live and it is reporting an SQL error which is most likely the problem, not your php header redirecting statement.

    View the HTML source after submitting your form.

    Also, I ran your script on my server and it redirected beautifully, but of course, since I didn't have your database I remarked the MySQL DB specific lines of code.

    The HTML source contained:
    'SQL1: Duplicate entry '06' for key 2'

    Typically if you expect '06' to be entered more than once into your table, the field in your database needs to allow duplicates... this might be fixed by making it so the field holding the '06' value is not indexed and is allowed to have duplicate fields. I use MSSQL Server, so I don't have any advice on changing the properties of the field in question.

    If you're convinced it's a header issue, obviously make sure the header location line if the first line of code to send data back to the client side. If you have any whitespace above your first <?php that can cause it to throw warnings (because the ouput is already started and headers need to come before normal HTTP output, otherwise you get one of these (which should be highly visible BTW):

    'Warning: Cannot modify header information - headers already sent by (output started at ...'

    but also check the source for this message too, as sometimes it's buried in a comment or a select HTML entity or other hiearchtically built HTML object that doesn't necessarily get drawn on the screen.

    Comment

    • warezguy05
      New Member
      • Oct 2006
      • 14

      #3
      Originally posted by tomongous
      Warezguy,

      The HTML source contained:
      'SQL1: Duplicate entry '06' for key 2'

      Typically if you expect '06' to be entered more than once into your table, the field in your database needs to allow duplicates... this might be fixed by making it so the field holding the '06' value is not indexed and is allowed to have duplicate fields. I use MSSQL Server, so I don't have any advice on changing the properties of the field in question.
      Thanks for putting effort in this :)

      The 06-thing is the place where people are able to enter their cellphone-number. Cellphonenumber s start with 06 in holland so thats why the 06 is already entered to make it more easy :) The cellphonenumber should be unique in the database by the way.

      Anyway, i'll try your suggestions and let know if it worked out or not.
      greets

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

        Ronald :cool:

        Comment

        • warezguy05
          New Member
          • Oct 2006
          • 14

          #5
          Originally posted by ronverdonk
          Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

          Ronald :cool:
          yes security is an important issue although the festival is fictional fortunately ;) is it useful to remove html/php tags by using the strip_tags function or aint that sufficient?



          2 tomongous;
          i removed some white spaces at the top of the page between 2 parts of php-code and it worked out. the redirection function is working again :)

          Comment

          • vssp
            Contributor
            • Jul 2006
            • 268

            #6
            If you want to headder working

            1. No html code berfore the header function
            2. No eco stement enter berfor the header function

            Thanks
            vssp

            Comment

            • exoskeleton
              New Member
              • Sep 2006
              • 104

              #7
              Good day Sir Ronald,

              i just read your reply...i would like to know how to secure the database as you said about sanitizing of the $_POST array variables...can you give me an idea how to do it? please..

              thank yo sir ronald

              Originally posted by ronverdonk
              Very dangerous: inserting data in your database straight from the $_POST and selecting from the database without any sanitizing of the $_POST array variables. You are prone to hackers!

              Ronald :cool:

              Comment

              • warezguy05
                New Member
                • Oct 2006
                • 14

                #8
                yeah im curious too :)

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Let me start with quoting an old web-developer's adagium about data coming in from an external source, either POST or GET: "NEVER TRUST ANYTHING THAT COMES FROM OUTSIDE".

                  It would go too far to describe to you, in extenso, the dangers of Cross Site Scripting, SQL injection or form spoofing, but maybe I may point you to one of the web security gurus, who knows a lot more about it then I do, Chris Shiflet.

                  Cross Site Request forgeries
                  Form spoofing
                  SQL Injection
                  Session hijacking

                  There are always hackers (destructive ones, in soccer they are called hooligans) looking for forms, sessions and url parameters that can be stolen, taken over and/or injected. That is why you must sanatise/cleanse any input coming from outside.

                  Ronald :cool:

                  Comment

                  Working...