Where to get ubuntu source code?

WordPress Plugin Development: How can I get the source code of a redirected page with wp_remote_get()?

  • I'm trying to get HTML source code of a page that is redirected from another url. localhost/redirects/index.php - redirects to localhost/redirected_page.php <meta http-equiv="refresh" content="0; url=http://localhost/redirected_page.php" /> localhost/redirected_page.php - just echos hello world. <?php echo 'hello world!'; Now, with wp_remote_get(),  I'd like to retrieve the source code of the destination page. This only  shows the contents of index.php. So how can I achieve this? <?php /* Plugin Name: Test WP Remote Redirect */ add_action( 'admin_menu', 'wp_remote_get_redirect_admin_menu' ); function wp_remote_get_redirect_admin_menu() { add_options_page( 'WP Remote Get Redirect', 'WP Remote Get Redirect', 'manage_options', basename( __FILE__, ".php" ), 'wp_remote_get_redirect_admin_page' ); } function wp_remote_get_redirect_admin_page() { ?> <div class="wrap"> <h1>WP Remote Get Redirect</h1> <?php $html = wp_remote_get('http://localhost/redirects/index.php'); echo htmlspecialchars( $html['body'] ); ?> </div> <?php }

  • Answer:

    wp_remote_get only follows HTTP redirects (i.e. in the HTTP header) -- it won’t follow a meta-refresh or javascript based URL modification as it doesn’t actually parse/render the content. To get the content of the destination page in this scenario, you’d need to check the HTML for a meta refresh tag, then remote_get the url in the content attribute -- recursively -- as the next page may also have a meta-refresh ;-) You can probably do that with strpos and a regex, but ideally you’d use a PHP HTML parser: http://htmlparsing.com/php.html Handling a JS based redirect is well... way too involved for a Quora answer. Good luck with that!

Nick Ciske at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.