Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the previous url using PHP

Suppose my site's url is given as hyperlink on some page on the internet; that page could be anything on internet - blog, orkut, yahoo, even stackoverflow etc, and someone clicks on it,and visited my site. So can we know, using php, the previous url from which the visitor came to my page?

like image 730
Nawaz Avatar asked Jan 11 '11 20:01

Nawaz


People also ask

How do I find the link to a previous page in Wordpress?

get_previous_posts_link( string $label = null ) Retrieves the previous posts page link.

What is $_ server [' Http_referer ']?

$_SERVER['HTTP_HOST'] Returns the Host header from the current request. $_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not reliable because not all user-agents support it)

How will you redirect a page using PHP?

How Redirection Works in PHP. In PHP, when you want to redirect a user from one page to another page, you need to use the header() function. The header function allows you to send a raw HTTP location header, which performs the actual redirection as we discussed in the previous section.


2 Answers

Use the $_SERVER['HTTP_REFERER'] header, but bear in mind anybody can spoof it at anytime regardless of whether they clicked on a link.

like image 147
BoltClock Avatar answered Oct 06 '22 01:10

BoltClock


$_SERVER['HTTP_REFERER'] is the answer

like image 32
Andreyco Avatar answered Oct 05 '22 23:10

Andreyco