0

E.g. I have two domains:

http://www.computer.com
http://www.computers.com

http://www.computer.com is main website and http://www.computers.com is just dummy that will redirect to main website (http://www.computer.com).

So my goal with pure PHP is to detect that user comes from http://www.computers.com rather than google or other website or directly typing url without using refer since it can be disabled.

Both sites are on same hosting, but I cannot access file system of one site from another. And $_SESSION is or $_COOKIE are domain specific variables too.

nickhar
  • 19,981
  • 12
  • 60
  • 73
Petja Zaichikov
  • 275
  • 3
  • 12

2 Answers2

3

You could set your redirect script to push to www.computer.com?ref=sister or some similar URL, then log accordingly and, if desired, redirect back to home to keep it transparent to the user.

Are you asking for an htaccess example though? Or just ideas on how to do it?

You say pure php in your computers.com index file:

    <?php 
    header("HTTP/1.1 301 Moved Permanently"); 
    header("Location: http://www.computer.com?ref=sister"); 
    ?>
Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • i said i dont want to use $_GET – Petja Zaichikov Dec 11 '12 at 01:55
  • no you didn't you said without using "refer" which is assumed to be $_SERVER['HTTP_REFERER'] - the common way many people check referrals. Don't want the ? then use uri segments. Explode on "/" and check to see if the first segment is whatever key you choose to give it. Don't like that? Then use htaccess to 301 and check your server logs. – Kai Qing Dec 11 '12 at 02:07
1

Your best bet is to to address your issues on multiple levels. First you should point DNS for www.computers.com to point at the IP address for www.computer.com. Now both of your requests are being served by the same server or cluster of servers(if behind a load balancer).

Second, if you actually want to rewrite the URL to utilize a single domain (to consolidate your cookies, sessions, etc.), then you could use webserver redirection (i.e. mod_rewrite for Apache) to redirect all the requests to the final domain.

Finally, in that rewrite, you should send 301 codes on rewrite to make sure that spiders and such know that this is a permanent redirection.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • +1 for good strategy! What we don't know is if the OP want's to see/log the traffic from the sister domain (eg. exactly how much traffic is coming from the sister site). – nickhar Dec 11 '12 at 00:57
  • @nickhar You could use rewrite_log to see redirections that occur or even just basic Apache logs. Also very easy to do the rewrite rulle to redirect `www.computers.com` to `www.computer.com?ref=computers.com` or whatever so that the PHP script can behave differently if it needs to. – Mike Brant Dec 11 '12 at 01:00
  • Yes, thats applicable too. We may find out in an updated question! ;) – nickhar Dec 11 '12 at 01:03
  • "What we don't know is if the OP want's to see/log the traffic from the sister domain (eg. exactly how much traffic is coming from the sister site)." --------- Yes get how many ppl go trough other domain. – Petja Zaichikov Dec 11 '12 at 01:55