I saw someone ask a question about detecting if a URL redirects from groovy and perl but couldn't find anything on PHP.
Anyone know of somewhere I could find that code that does this?
Create a Session variable when a user visits page1. php, then on page2. php check if that session variable exists. If so, then the user was redirected from page1.
You also need to make sure that people actually visit the HTTPS version of your site, which means using a 301 redirect between the HTTP and HTTPS version. To check that this redirect is in place, go to your homepage and look at the URL bar. You should see https://[www].yourwebsite.com/, plus a lock icon.
URL redirection, also known as URL forwarding, is a technique to give more than one URL address to a page, a form, or a whole Web site/application. HTTP has a special kind of response, called a HTTP redirect, for this operation.
$ch = curl_init('http://www.yahoo.com/');
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (($code == 301) || ($code == 302)) {
//This was a redirect
}
Actually, I found this works best:
function GetURL($URL)
{
$ch = curl_init($URL);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $code;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With