Get page redirect URL


/ Published in: PHP



Copy this code and paste it in your HTML
  1. $url = 'http://google.com';
  2. $ch = curl_init();
  3. curl_setopt ($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_HEADER, true);
  5. curl_setopt($ch, CURLOPT_NOBODY, true);
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  7. $response = curl_exec($ch);
  8.  
  9. $header = "Location: ";
  10. $pos = strpos($response, $header)+strlen('Location: ');
  11. $redirect_url = substr($response, $pos, strpos($response, "
  12. ", $pos)-$pos);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.