473,499 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting the previous url

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
5 26768
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2241
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
3
1885
by: serge | last post by:
I am using SQL Server 7 SP4. I have created a blank database in which i am trying to import using DTS wizard all tables/views/stored procedures without any DATA (records). I keep getting...
5
1797
by: Peter | last post by:
I am looking for a data structure that I need to use as follows. Suppose I am looking for node A. When I perform a lookup for node A I also want information about the node previous to node A( as...
1
3200
by: msnews | last post by:
Hi All, My client has following request. I am not sure how to do it. Dynamically from database, we are getting set of images names. Now we want to display them with next and previous buttons....
4
4132
by: devi | last post by:
Hi, In oracle I have a LAG function using which I could get the previous value of a field. Do we have anything similar to that in SQL Server or access? Thanks Devi
7
2066
by: Hitesh | last post by:
Hi, I have a small script here that goes to inside dir and sorts the file by create date. I can return the create date but I don't know how to find the name of that file... I need file that is...
0
919
by: Maximus | last post by:
Hi to all, i am getting unable to cast error while using Me.previous page in asp.net 2.0 . i am using previous page object to getting values from public properties of previous page and i am...
1
2404
by: Reb | last post by:
Hi all, I have not successfully found a Javascript sample for getting next and previous links from a file... I figured that someone must have solved this problem already! ... here is what I'm...
1
2387
by: patronise | last post by:
My problem is that I'm wrestling to make the LoadMovie and UnloadMovie functions work for me. Here is the layout of my flash file: I've got several seperate flash files and I can jump to any one of...
0
1102
by: navinkumarnischal | last post by:
From page1 i am redirecting to page2 in this pageload event i am redirecting to page3. In page3 if i give page.urlreffer the i will get page1 url but i want page2 url here how to get it and I...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.