मैंने एडम बैकस्ट्रॉम के जवाब को संशोधित किया और चिबोर्ग सुझाव लागू किया। (केवल HEAD डाउनलोड करें)। इसमें एक और चीज है: यह जांच करेगा कि क्या एक ही सर्वर के एक पृष्ठ में पुनर्निर्देशन है या बाहर है। उदाहरण: terra.com.br terra.com.br/portal पर रीडायरेक्ट करता है। PHP इसे रीडायरेक्ट की तरह विचार करेगा, और यह सही है। लेकिन मैं केवल उस यूआरएल को सूचीबद्ध करना चाहता था जो किसी अन्य यूआरएल पर रीडायरेक्ट करता है। मेरी अंग्रेजी अच्छी नहीं है, इसलिए, अगर किसी को समझने में कुछ मुश्किल लगता है और इसे संपादित कर सकता है, तो आपका स्वागत है।
function RedirectURL() {
$urls = array('http://www.terra.com.br/','http://www.areiaebrita.com.br/');
foreach ($urls as $url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// chiborg suggestion
curl_setopt($ch, CURLOPT_NOBODY, true);
// ================================
// READ URL
// ================================
curl_setopt($ch, CURLOPT_URL, $url);
$out = curl_exec($ch);
// line endings is the wonkiest piece of this whole thing
$out = str_replace("\r", "", $out);
echo $out;
$headers = explode("\n", $out);
foreach($headers as $header) {
if(substr(strtolower($header), 0, 9) == "location:") {
// read URL to check if redirect to somepage on the server or another one.
// terra.com.br redirect to terra.com.br/portal. it is valid.
// but areiaebrita.com.br redirect to bwnet.com.br, and this is invalid.
// what we want is to check if the address continues being terra.com.br or changes. if changes, prints on page.
// if contains http, we will check if changes url or not.
// some servers, to redirect to a folder available on it, redirect only citting the folder. Example: net11.com.br redirect only to /heiden
// only execute if have http on location
if (strpos(strtolower($header), "http") !== false) {
$address = explode("/", $header);
print_r($address);
// $address['0'] = http
// $address['1'] =
// $address['2'] = www.terra.com.br
// $address['3'] = portal
echo "url (address from array) = " . $url . "<br>";
echo "address[2] = " . $address['2'] . "<br><br>";
// url: terra.com.br
// address['2'] = www.terra.com.br
// check if string terra.com.br is still available in www.terra.com.br. It indicates that server did not redirect to some page away from here.
if(strpos(strtolower($address['2']), strtolower($url)) !== false) {
echo "URL NOT REDIRECT";
} else {
// not the same. (areiaebrita)
echo "SORRY, URL REDIRECT WAS FOUND: " . $url;
}
}
}
}
}
}
रीडायरेक्ट कैसे? क्या ग्राहक से बुलाया? लॉग इन होने पर या लॉग इन नहीं होने पर? किस लिए? क्या स्क्रिप्ट को सत्र कुकीज़ और अन्य जटिल चीजों को संभालना होगा? –
कृपया "पुनर्निर्देशित यूआरएल" को परिभाषित करें। –
देखें [मैं कैसे निर्धारित कर सकता हूं कि एक यूआरएल PHP में रीडायरेक्ट करता है?] (Http://stackoverflow.com/questions/427203/how-can-i-determine-if-a-url-redirects-in-php/481377# 481377) –