[英]PHP: redirect after get url
我需要“計算” URL並重定向到它。 我有以下代碼:
<?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."'");
?>
首先在$ imgurl中獲取URL,然后重定向到該URL ...但是它不起作用。
有什么想法或建議嗎? 謝謝
header("'Location:".$imgurl."'");
應該可能是:
header("Location: " . $imgurl);
我刪除了單引號'
因為您的HTTP標頭如下所示:
'Location: http://site.com/image.jpg'
由於單引號無效。
您還正在循環查找許多圖像URL,但是僅重定向到最后一個URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.