phpbrowserscriptable

php scriptable web browser


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

I want to detect four kinds of redirects:

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?


Solution

  • 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...