Forum Moderators: coopster

Message Too Old, No Replies

PHP to capture refering page name

         

kapow

5:24 pm on May 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a site with hundreds of product pages e.g. blue-widget.htm, red-widget.htm...
and an enquiry form: enquire.php.

Is there php code to capture the refering page name e.g. blue-widget.htm and display it in the enquiry form e.g. <? echo: $refpage;?>

Usually I would simply use: <a href="enquire.php?subject=blue-widget">Enquire</a>
However, there is only one copy of the menu for this website, the menu is 'included' in every page, and the menu has the enquire button :(

dreamcatcher

7:38 pm on May 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo $_SERVER['HTTP_REFERER'];

That any good?

Span

7:55 pm on May 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No that's no good.. the refering page is not the page where the form is send from but the page where the user came from. Better use $_SERVER['PHP_SELF'];

kapow

1:12 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So which of those is right?
I want enquire.php to echo blue-widget.htm ie the page the visitor was on when they clicked enquire.php.

jatar_k

4:18 pm on May 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if it is in a menu file, should make it even easier, pass it a value or set up the value before you include the menu.

of the above $_SERVER['HTTP_REFERER'] is the right one if you want to use it on the enquire.php page to find out what the last page was.

$_SERVER['PHP_SELF'] would be right if you wanted to build the link on the page that is linking to enquire.php

either way you will have to chop it up a bit to get what you want

kapow

6:09 pm on May 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Jatar_k
if it is in a menu file, should make it even easier, pass it a value or set up the value before you include the menu.

This sounds good. However, I should have explained a bit more:
- my customer is using a CMS to update/create product pages. To '..pass it a value or set up the value before you include the menu' My customer must add the 'Product name' to new pages.
- The CMS does not display/edit php code.
- I have set .htaccess so .htm pages parse php (the CMS will edit such htm pages but not show/edit php code that is within them).
- The CMS will edit html items e.g. <input type=hidden name="product" value="Blue widget">

If I understand your point: php is parsed before html, so I don't think this will work: <input type=hidden name="product" value="Blue widget">
Is there another way to do that?

jatar_k

7:06 pm on May 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



in the menu itself you could use PHP_SELF to add a value to the enquire link, then it would work for every page

is the menu php parsed?