Question

I'm not a php coder but I need a script for this situation:

xyz.com redirects to abc.com/index.html, then this redirects to abc.com/index.php

But the URL in the address bar stays xyz.com the whole time, so I want a text field of my form in index.php to show xyz.com as referrer how do I do it through php or java.

And I can't make changes to xyz.com as I don't host a site there, it's just forwarding to abc.com/index.html

This is the script:

<?php 

   $server=$_SERVER['HTTP_REFERER'];

   echo $server;

?>

It keys in abc.com/index.html in the textfield. How do i get xyz.com?

Was it helpful?

Solution

The Referer HTTP header is usually used for this purpose. This Stack Overflow question deals with fetching that Header from a PHP file:

How do you get the 'referer' header in PHP?

The trick may be making sure that the header is included in the redirect from your html page to your php page. There is another Stack Overflow discussion about this:

Will a 302 redirect maintain the referer string?

In general, if you have control over the index.html page and the server that hosts it, you should be able to find a way to accomplish what you are trying either programatically or via server configuration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top