PHP how to detect user coming from sister website if referrer disabled - php

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.

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");
?>

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.

Related

Subdomains redirection

With my current PHP knowledge, I know how to create a subdomain automatically via Plesk api when a user is created on my site. I can then redirect the user.example.com to example.com/user via htaccess.
My question that I cannot figure out how to do, is how to redirect but also keep user.example.com in the navigation bar, not the example.com/user ?
I own a dedicated hosting environment so I have access to change pretty much any setting that I like.
Here are some suggestions:
Don't use .htaccess for this. A very common use of .htaccess is to redirect all requests to a central file (generally index.php).
In order to allow dynamic subdomains you need to make sure your virtual host is configured properly for that.
And in order to redirect to the subdomain url you can use the built-in php function header.
Example:
header('Location: '.$subdomainUrl);

laravel app in iframe keeps refreshing the session

Our website https://www.diamir.de is build with laravel. when we try to load the site in an iframe on another domain, the session is regenerated with every request. the session cookie is send to the browser. but it seems laravel is not able to read it on the next request and therefore regenerates the session.
how can we enable sessions when the site is loaded in an iframe on another domain? is this even possible with the security settings in modern browsers?
thanks.
iFrames are largely locked down windows to view other content inside your website. They were a useful way of hacking things into sites, but have been replaced in a lot of scenarios.
For your particular scenario, showing the site fully on another domain, there are other, better ways to reference the same site from multiple domains.
Personally, I'd redirect in most scenarios, all where an iFrame would work. This results in a user going to any secondary domain, and being redirected to the primary domain. Usually done with a 301 permanent redirect.
However, the one occasion where I need the site sitting on multiple domains is when the site is themed on other domains. In a lot of these cases, it's preferable to fork the site and make changes as needed, but in those that need the same code base and just a theme over the top, I'd simply have the server (Apache, NGINX, or any other server) listen to multiple domains all serving the same site.

Tracking redirects Apache/PHP

Is there a way in PHP to know if the current script (page) came from an apache 301 redirect?
Additional details to set the stage for this question:
We just completed a website merge, retiring one web site and sending it's traffic to a similar sister website which included 100s of individual 301 redirects for products, categories. We would like to track transactions that originated from the retired website URLs vs those originating from the current URL. Basically, as an order completed, we want to know which URL it had originated from, redirected from the old vs direct traffic from the new.
Currently the 301 redirects are performed via a separate file included in the httpd.conf file. This separate file contains 100s of "Redirect 301 /source /destination" directives.
My plan was to have PHP sniff out these redirects, store the original URL domain as a session variable, then access that session variable at order completion in order to connect it to that original domain.
For this to work, the landing page script would need to know if it is the result of a redirect. Which leads to the question: Is there a way in PHP to know if the current script (page) came from an Apache 301 redirect?
Thanks in advance for your help.

Does a crawler like googlebot 'see' my rewritten urls?

I'm using htaccess to rewrite and redirect www.mysite.com/index.php?id=# to friendly urls like www.mysite.com/news. So all news-articles will be written as www.mysite.com/news/article1, etc.
Now I'm blocking off all directories on my server that it doesn't need to index with robots.txt. Since I'm using a cms these are directories like /core, /managers, /connectors, etc. But since the www.mysite.com/news directory doesn't actually exist, but is rewritten with htaccess, will blocking off all the directories like /core, etc. still allow a crawler to index my website?
So basically what I want to know is: does a crawler see my website urls as they are after they're rewritten? Or does it still need access to the other directories of my cms, like /core to be able to index my pages?
No, the rewritten URL is an internal mapping process only. It is only used by your web server to determine how to treat the user-friendly URL it receives.
The same way the URL remains unchanged in a browser address bar, the process is invisible to the client, be it a web browser or a bot.
URL Rewriting is not to be confused with Redirection. In the latter case, a client request receives a "301 Redirect" response containing the URL where the actual resource resides. This results in a second request from the client to the redirected URL. Then by definition the client will be aware of this process.

Permanent URL masking for mirroring website using php and htaccess

First
Let say that i have www.domain.com that are client site and user login and do all the thing that he want (site is main and he use POST method for login adn other things and HEADER redirect if login are success)
But i not want user to see original www.domain.com i want when they enter www.name.com/dashboard.php to see content from www.domain.com/dashboard.php but him URL bar to show www.name.com/dashboard.php ..and like this all other page that can have original www.domain.com
I found this site:
http://www.htmlremix.com/css/permanent-url-masking-for-mirroring-website-using-php-and-htaccess
Adn use script but when are entered user login detail noting happen!! Just home page reload.
I try everything that i think may be cause problem and not found how to solv it .. So please help me!!
Thanks Allot
P.S. If have some more good way that can i use also will help me!
that cant be achieve with a htaccess file.
You need different things.
possible solution could be:
apache mod proxy so you could proxy everything through that url.
the other way could be a php written some kind of proxy. Working with curl or and remote configured fopen.
But be careful to also send the post data and the cookies, otherwise the user session could not be handled if its cookie based.
If both domains are on the same server you could easily set this up with a vhost configuration in apache/nginx what ever you are using.

Categories