Posted By

sybrex on 10/05/11


Tagged

curl php redirect


Versions (?)

Get page redirect URL


 / Published in: PHP
 

  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. curl_close($ch);
  9.  
  10. $header = "Location: ";
  11. $pos = strpos($response, $header)+strlen('Location: ');
  12. $redirect_url = substr($response, $pos, strpos($response, "
  13. ", $pos)-$pos);

Report this snippet  

You need to login to post a comment.