By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

getting the previous url

P: n/a
hi,

Is it possible to get the previous url. For example, if I am on page -
page01.php - and I then click to - page02.php - from page02.php, can I
use script to determine that I have come from page01.php? It doesnt
have to be the entire url, even just the file name. Cheers

Burnsy
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
mr_burns wrote:
Is it possible to get the previous url. For example, if I am on page -
page01.php - and I then click to - page02.php - from page02.php, can I
use script to determine that I have come from page01.php? It doesnt
have to be the entire url, even just the file name. Cheers


The only reliable way you can get it is to pass it as a parameter to the
page eg your link would be page02.php?referer=page01.php, or use some
form of non-cookie sessions (which also require a parameter to be
passed in the url eg page02.php?sessid=123) and track it in a database.

You can use $_SERVER['referer_url'] but this is not always set; some
users have browser preferences or other software which prevents the
referal informtion being passed to the server for privacy/security
reasons.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
mr_burns wrote:
Is it possible to get the previous url. For example, if I am on
page -
page01.php - and I then click to - page02.php - from page02.php, can
I
use script to determine that I have come from page01.php?


You use $_SERVER["HTTP_REFERER"] ... however it must be noted that as
with *anything* that comes from client, this is unreliable
information; user can set it to whatever with the right tools. You
also can not rely that this information exists at all. Most of the
time it does, but if your system hangs up just because this info isn't
available, you're just putting yourself into a lot of trouble.

--
Markku Uttula

Jul 17 '05 #3

P: n/a
Hi,

Yeh, $_SERVER["HTTP_REFERER"] didnt return anything. I have tried
using instead, $_SERVER["PHP_SELF"], and that does the trick.

Is there anything I should be aware of when using $_SERVER["PHP_SELF"]?
Its really just for a simply 'send page to a friend'. If somebody was
to mess up the from address, it wouldnt do them any favours.

Burnsy

Jul 17 '05 #4

P: n/a
bi******@yahoo.co.uk wrote:
Yeh, $_SERVER["HTTP_REFERER"] didnt return anything. I have tried
using instead, $_SERVER["PHP_SELF"], and that does the trick.


Umm... PHP_SELF is the *current* page ... I understood you wanted to
know the page from which the user came to the current page.

--
Markku Uttula

Jul 17 '05 #5

P: n/a
mr_burns wrote:
Is it possible to get the previous url. For example, if I am on page - page01.php - and I then click to - page02.php - from page02.php, can I use script to determine that I have come from page01.php? It doesnt
have to be the entire url, even just the file name. Cheers


Add this line in the beginning of every script or possibly using a
global-common include file say config.php

output_add_rewrite_var('referer',
htmlspecialchars($_SERVER['PHP_SELF']));

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.