Page 1 of 1

Passing the current filename to a new file

Posted: Wed Sep 25, 2002 6:50 pm
by nike
Hi,
I`m a newbie, so if I´m wrong to post my question here,
please don`t kill me right away, direct me to the right forum,
if you could please be so nice.

My problem:
I would like to create a general Feedback form, that applies
to all my webpages, so I can include a sentence at the bottom,
like for feedback, please click here
When the user clicks on the link, the user should be take
to a new page (my feedback page) and the name of the page,
from which the user came should be taken with the jump to the
feedback page.
How can I do that with php?
I want to include the name of the originating page in the feedback
form, so I don`t have to write a form for each page...
The feedback form will include a Subject line, into which I would like
to put/parse the name, but I guess that`s the next step.

Help would be nice, or if you could point me to a similar tutrial if available.

Bye

Nike

Posted: Wed Sep 25, 2002 7:04 pm
by volka
$_SERVER['HTTP_REFERER']
'HTTP_REFERER'
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Thank you

Posted: Thu Sep 26, 2002 12:25 am
by nike
Hi,
thank you for the info.
could you describe a little bit more, how I use it?
Do I put this into the link or into the page that is being opened?
Bye

Nike

Posted: Thu Sep 26, 2002 7:20 am
by volka
$_SERVER is a superglobal that is set for you by PHP on script-entry (check the manual and your php-version if this appropiate for you)

$_SERVER['HTTP_REFERER'] (if set) contains the string the client transmitted.
If the link to your script the user activated is i.e. on the page http://my.host/whatever.html $_SERVER['HTTP_REFERER'] should contain 'http://my.host/whatever.html'

put

Code: Select all

<?php
if (isset($_SERVERї'HTTP_REFERER']))
  print 'HTTP_REFERER = '.$_SERVERї'HTTP_REFERER'];
else
  print 'no HTTP_REFERER given';
?>
in your feedback.php to see how it works.

Next step is to create a form for the feed back. try something like

Code: Select all

<html><body>I'm sorry you have something to complain about.....bla bla bla 
<form action ... method ... >
  <input name="source" <?php
     if (isset($_SERVERї'HTTP_REFERER']))
        print 'type="hidden" value="'.$_SERVERї'HTTP_REFERER'].'"';
     else
        print 'type="text";
   ?> />
   <br/>
   <input name="desc" type="text" />
   ...
</form>
...
in your feedback.php. If HTTP_REFERER has been given, it's value ('the calling page') is kept as hidden value within the form. If not, a text field where the user can type the url is added to the form.

Just as remark: it's (obviously) only a very basic code-snippet.
i.e. in the print-statement you should encapsulate $_SERVER['HTTP_REFERER'] with htmlentities(), in 'processing' script you may check the url (could be something that does not belong to you) and so on and so on

Thank you - exactly what a newbie needs ;-)

Posted: Thu Sep 26, 2002 11:47 am
by nike
Hi,
thank you very much.
Your explanation and example really
helped me get on with what I am planning to code.

Sometimes it`s those very obvious (for the trained)
little easy things, that are the hardest for the newbies ;-)
Thanks again.

Bye

Nike