简体   繁体   中英

PHP: redirect after get url

I need "calculate" an URL and redirect to it. I have the following code:

<?php

//Basic HTML parsing with PHP
    include("simple_html_dom.php");

    $htmlCode = file_get_html('http://example.net/example.html');

    foreach($htmlCode->find('div[class=frontPageImage]') as $element) {

        foreach($element->find('img') as $imagee)
            $imgurl = $imagee->src;
    }

header("'Location:".$imgurl."'");

?>

First in $imgurl get the url and later redirect to that url... but it doesn't work..

any idea or suggestion? thanks

header("'Location:".$imgurl."'");

Should probably be:

header("Location: " . $imgurl);

I removed the single quote ' because your HTTP header would look like:

'Location: http://site.com/image.jpg'

which is invalid because of the single quotes.

You are also looping and finding many image URL's but only redirecting to the last one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM