0

I used below function to get redirected (final) url of these links

http://iprice.my/coupons/zalora/

function curlFileGetContents($url)
   {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0');

      $result = curl_exec($ch);
      $info   = curl_getinfo($ch);

      $effectiveUrl = $info['url'];

      curl_close($ch);


      return $effectiveUrl;
   }

but I couldn't get anything, I wonder why? Eg I did curlFileGetContents('http://iprice.my/coupons/zalora/#007b9a6024d19edec91d04c2e92e143e744c83b6');

Elton Jamie
  • 586
  • 6
  • 17

1 Answers1

0

The URL isn't being redirected - the links you are referring to (that only spawn on that page) are pop unders. A look at the curl header shows the URL is not being re-directed:

curl --head http://iprice.my/coupons/zalora/#007b9a6024d19edec91d04c2e92e143e744c83b6
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.9-1ubuntu4.9
Cache-Control: no-cache
Date: Fri, 22 May 2015 15:06:31 GMT
X-iPrice-Cached: 1
X-iPrice-Cached-Type: Response

The approach you currently have won't work for what you want to do.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Any idea how to get the final link? you try to click the links on http://iprice.my/coupons/zalora/, there's a tab opened in the left. How to get that links? – Elton Jamie May 22 '15 at 15:21
  • That's the `pop under` which is spawned via `javascript` when you click the link on that page. You'd have to come up a `scraper`, `robot`, or use another tool that would essentially click those links and record where they go. `Curl` wouldn't be of much help for that since it can't really follow `javascript` links on it's own. – l'L'l May 22 '15 at 15:31
  • I'd saw someone did it with curl, seriously. – Elton Jamie May 22 '15 at 15:32
  • If you've seen it done then why are you asking about it? `Curl` on it's own cannot follow JS links: http://stackoverflow.com/a/4454624/499581 – l'L'l May 22 '15 at 15:34
  • As I said before, you'd have to implement some type of a `scraper` (see comment #2) to parse the `html` and `javascript` which likely won't be easy. [Here's one such attempt at it](http://stackoverflow.com/a/10168444/499581), (see the commented code `/ Create a new DOM Document to handle scraping`). As for your original question here, you have the answer — so you might consider opening another question in regards to following `javascript` links. – l'L'l May 22 '15 at 15:57