0

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?

  • If the URL in the address bar stays xyz.com the whole time, then you're not really doing a redirect. Are you actually proxying the request through to abc.com, via mod_rewrite or mod_proxy or something similar (depending on what web server you are using)? If you are proxying the request, the X-FORWARDED-FOR header might give you what you need. – djmorton Apr 28 '14 at 00:49

1 Answers1

0

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.

Community
  • 1
  • 1
djmorton
  • 616
  • 4
  • 6
  • thanks for your response, but i got access to xyz.com so i redirected it directly to index.php so this script works $server=$_SERVER['HTTP_REFERER']; –  Apr 28 '14 at 05:58