1

i have a php script named as "abc.com/autologin.php". This autologin.php is hyperlinked to a button on another web portal def.com. so when a user on def.com click the button he visit abc.com/autologin.php.

So in autologin.php i want to fetch the url of the page where that button is clicked. Url is dynamic as it contains parameters different for different users.

prem
  • 241
  • 2
  • 11

4 Answers4

1

You can use $_SERVER global variable to find referrer details.

$_SERVER['HTTP_REFERER']
Aiyaz Khorajia
  • 598
  • 2
  • 11
0

$_SERVER['HTTP_REFERER'] will give you the referrer page's URL if there exists any.

Farsheel
  • 610
  • 6
  • 17
0

Since URL cannot be fetched from the server side, it's better to use client side to get the URL. Also, it's slightly unreliable to rely on $_SERVER['HTTP_REFERER']. As always the request goes to the same PHP file, it's better to add a hidden input field which explicitly says from which URL, the request is originating.

<input type="hidden" name="fromPage" value="feedbackForm" />
<input type="hidden" name="url" value="https://www.example.com/feedback.html" />

And then capture them in your REQUEST data using:

$_REQUEST["fromPage"]
$_REQUEST["url"]
Soolie
  • 1,812
  • 9
  • 21
  • can you just elaborate please. you mean to say i have add input field to the autologin.php . how to fetch the dynamic url. – prem Nov 21 '17 at 09:16
  • @prem I just told you can capture them in your `REQUEST` data using: `$_REQUEST["fromPage"]` and `$_REQUEST["url"]`. Do you know PHP or not? – Soolie Nov 21 '17 at 09:24
  • my mistake i didn't see it. – prem Nov 21 '17 at 09:39
0

You can use $_SERVER['HTTP_REFERER'] for more info http://php.net/manual/en/reserved.variables.server.php

Moorthy
  • 45
  • 8