Forum Moderators: open

Message Too Old, No Replies

Redirection question

         

glamdring

1:36 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Hi, I wonder if someone can tell me if this is possible, as I dont know myself.

I have a page on my site from which people go through to a contact form. This first page sends a couple of hidden fields through to the contact page, which is written in php.

Once they've submitted their details (which writes them to a SQL db), I'd like to know if its possible to have them automatically re-directed to another page - the URL of which is generated by the FIRST page.

In other words, they come from page1.htm and go to contact.php. Upon submit of contact.php, I'd like them to go to a URL which is generated by page1.htm : hence, if they approach by page2.htm instead of page1.htm, page2.htm sends them to a different URL than page1.htm does.

Are you still with me? Can I do this?

Thanks a lot.

Birdman

1:57 pm on Jun 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure, it can be done! If it were me, I would send the destination URL along to contact.php as a GET parameter. Like this:

<a href="/contact.php?url=/somewhere.php">Contact us</a>

Then, in the <form>(contact.php), write that variable into a hidden form field. Like this:

<input type="hidden" name="url" value="<?php print($_GET["url"]);?>" />

Finally, in the script that writes to the db, add a redirect header at the end of the script. Like this:

header("Location: ".$_POST["url"]);

That should do it for you.

glamdring

4:43 pm on Jun 16, 2004 (gmt 0)

10+ Year Member



Brilliant. Just what I was after - thankyou.