Forum Moderators: coopster

Message Too Old, No Replies

Capture current URL

using a php form

         

lj2007

2:10 pm on Aug 15, 2007 (gmt 0)

10+ Year Member



Hi,

Probably a simple answer to this...

I am writing a simple PHP contact form. The form is in an include that will be in the header of every page in the website. When the form is submitted I want the user to be returned to whichever page they came from. Therefore in the <form action="" method="post"> i want the action="" to point to the URL that the user is currently on - how do i do this?

Thanks!

dreamcatcher

2:21 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

Or you might need the full url.

dc

whoisgregg

3:12 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Capture the user's current page through a hidden input:

<form action="/path/to/processing_script.php" method="post">
<input type="hidden" name="return_to" value="<?php echo $_SERVER['REQUEST_URI'];?>" />
</form>

Then, in the processing script:

if($form_submitted_successfully){
header('Location: http://'.$_SERVER['SERVER_NAME'].$_POST['return_to']);
}

[edited by: eelixduppy at 4:00 pm (utc) on Aug. 15, 2007]
[edit reason] delinked code [/edit]

PHP_Chimp

4:27 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you dont want to use a hidden input then just use, on the processing page, the $_SERVER['HTTP_REFERER'] to get the refering page.

[edited by: PHP_Chimp at 4:31 pm (utc) on Aug. 15, 2007]

whoisgregg

5:17 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only drawback to using HTTP_REFERER is that it won't always be set as it depends on the client sending that information.

lj2007

10:10 am on Aug 16, 2007 (gmt 0)

10+ Year Member



Thanks!

How would i do the same sort of thing but with the page title. The title of each page is different so how could I capture the title of a certain page and display it further down. A need a script that i can place on any page...

Thanks again!

Habtom

10:14 am on Aug 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How would i do the same sort of thing but with the page title.

How are you displaying the title in the first place?

Is it something like the following:

<title> echo $title </title>

then you can use $title on the rest of the page.

If you post part of your code including this part, you might get a better response.

Habtom