2

I want a url redirect tracer function in the php such as http://www.wheregoes.com/ .

I want to detect four kinds of redirects:

  • Http 301 redirect
  • Http 302 redirect
  • meta tag redirect
  • javascript redirect

If i use curl, i can easily detect 301, 302 redirect, but it is difficult to detect the other two redirections.

So i want a scriptable web browser, i will use a library as below:

$browser = Browser::createBrowser('chrome');
$delay = 10; // (This is a important parameter for detecting javascript or meta tag redirection).

$browser->load($url, $delay, function onLoadComplete($arr_track_url){
    print_r($arr_track_url);
});

I searched and ran into some libraries such as http://www.simpletest.org/en/browser_documentation.html, but they don't support javascript and meta tag redirect.

Is there any php scriptable browser? Or can i detect javascript or meta tag redirection easily?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Danil Chernokalov
  • 755
  • 1
  • 10
  • 31
  • possible duplicate of [Non-browser emulation of JavaScript - is it possible?](http://stackoverflow.com/questions/1768717/non-browser-emulation-of-javascript-is-it-possible) – Ja͢ck Feb 22 '13 at 06:31
  • [`` tags are still easy](http://php.net/manual/en/function.get-meta-tags.php), JavaScript redirects are pretty hard. – Ja͢ck Feb 22 '13 at 06:32
  • I think Non-browser emulation is too heavy for my request. Because i don't want parsing css, draw html and so on. I need only redirection of html. Is there any cool solution for this? – Danil Chernokalov Feb 22 '13 at 06:54

1 Answers1

2

If I get that right you want to find out where some link finally leads to, if that final url differs from the url actually clicked in the first place?

If so I think the best approach is to let the browser do its work and loko afterwards where it came out. This way you get exactly the 'normal' behaviour of a browser, not that of some library.

Use a (hidden) iframe where you load the url into. Then wait for a window.load event or something and query the documents location afterwards. I didn't try that now, but sounds doable to me...

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • I also think it can't solve some library code so easily. But how can i interactive browser instance with php? – Danil Chernokalov Feb 22 '13 at 06:43
  • Well not sure what you refer to with 'library'... But it certainly does everything a browser would do and that should be the final target. Or did I missunderstood your question? – arkascha Feb 22 '13 at 06:44
  • I want to develop a site like http://www.wheregoes.com/ with php, but it not support meta tag redirect and javascript redirect. How can i detect all the redirection on the server side? – Danil Chernokalov Feb 22 '13 at 06:52
  • Ah, so you want to work on the server side, I understood you meant on the client side. Anyway, same approach: use a headess browser instead of an iframe. A headless browser that implements javascript. – arkascha Feb 22 '13 at 06:58