Get previous url in php and javascript


//code for index.php

<a href=”previous-url.php”>click for php</a>
<a href=”previous-url-javascript.php”>click for javascript</a>

//code for previous-url.php

echo $a=$_SERVER[‘HTTP_REFERER’];

//code for previous-url-javascript.php

<button onclick=”goBack()”>Go 2 pages back</button>

<p>Notice that clicking on the “Go 2 pages back” button here will not result in any action, because there is no previous URL in the history list.</p>

function goBack() {
window.history.go(-2);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s