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.

2
  • I believe this is the answer you searching for: stackoverflow.com/a/4662120/8807094 Commented Nov 21, 2017 at 9:07
  • @Kussensloop It's not reliable. Commented Nov 21, 2017 at 9:24

4 Answers 4

1

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

$_SERVER['HTTP_REFERER']
Sign up to request clarification or add additional context in comments.

Comments

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"]

3 Comments

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 I just told you can capture them in your REQUEST data using: $_REQUEST["fromPage"] and $_REQUEST["url"]. Do you know PHP or not?
my mistake i didn't see it.
0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.