Last active
January 19, 2016 15:33
-
-
Save wisecrab/1137b73f01d13f295be6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function checkForRedirects($URL) { | |
| $ch = curl_init($URL); | |
| curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
| curl_exec($ch); | |
| $original_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true); | |
| curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); | |
| curl_exec($ch); | |
| $original_url = $URL; | |
| $destination_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); | |
| $destination_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| $redirect_count = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT); | |
| $page_size = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD); | |
| curl_close($ch); | |
| $code = array( | |
| 'original_url' => $original_url, | |
| 'destination_url' => $destination_url, | |
| 'original_status_code' => $original_status_code, | |
| 'destination_status_code' => $destination_status_code, | |
| 'redirect_count' => $redirect_count, | |
| 'page_size' => $page_size, | |
| ); | |
| return $code; | |
| } | |
| $page_status = checkForRedirects('http://yahoo.com'); | |
| var_dump($page_status); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment