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?

3
  • possible duplicate of Non-browser emulation of JavaScript - is it possible? Commented Feb 22, 2013 at 6:31
  • <meta> tags are still easy, JavaScript redirects are pretty hard. Commented Feb 22, 2013 at 6: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? Commented Feb 22, 2013 at 6:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I also think it can't solve some library code so easily. But how can i interactive browser instance with php?
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?
I want to develop a site like 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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.