簡體   English   中英

如何在PHP中打開URL而不進行重定向

[英]How to open url in php without redirect

我需要有關PHP的幫助,我想打開URL以從get-listing.php獲取完整的輸出。

我嘗試了這個:

<?php
  $url = file_get_contents("http://testbox.elementfx.com/get-listing.php");
  echo $url;
?>

它會顯示一個空白頁,但是如果我使用這個:

<?php
  header('Location: http://testbox.elementfx.com/get-listing.php');
?>

它將把我重定向到get-listing.php,我將獲得完整的輸出。

如果打開get-listing.php網址,我將看到完整的輸出,如下所示:

101 ABC FAMILY

http://testbox.elementfx.com/get-listing.php?channels=ABC FAMILY&id=101

Stream 1
102 CBS

http://testbox.elementfx.com/get-listing.php?channels=CBS&id=102

Stream 1
103 CNN USA

http://testbox.elementfx.com/get-listing.php?channels=CNN USA&id=103

Stream 1
105 ESPN USA

http://testbox.elementfx.com/get-listing.php?channels=ESPN USA&id=105

Stream 1
106 FOX News

http://testbox.elementfx.com/get-listing.php?channels=FOX News&id=106

Stream 1
107 Animal Planet

http://testbox.elementfx.com/get-listing.php?channels=Animal Planet&id=107

Stream 1
108 USA Network

http://testbox.elementfx.com/get-listing.php?channels=USA Network&id=108

Stream 1
110 SPIKE

http://testbox.elementfx.com/get-listing.php?channels=SPIKE&id=110

Stream 1
111 BRAVO USA

http://testbox.elementfx.com/get-listing.php?channels=BRAVO USA&id=111

Stream 1
112 BRAVO1

http://testbox.elementfx.com/get-listing.php?channels=BRAVO1&id=112

Stream 1
113 BRAVO2

http://testbox.elementfx.com/get-listing.php?channels=BRAVO2&id=113

Stream 1
114 BRAVO3

http://testbox.elementfx.com/get-listing.php?channels=BRAVO3&id=114

Stream 1
115 BRAVO4

http://testbox.elementfx.com/get-listing.php?channels=BRAVO4&id=115

Stream 1
116 BRAVO5

http://testbox.elementfx.com/get-listing.php?channels=BRAVO5&id=116

Stream 1
117 BRAVO6

http://testbox.elementfx.com/get-listing.php?channels=BRAVO6&id=117

Stream 1
118 BRAVO7

http://testbox.elementfx.com/get-listing.php?channels=BRAVO7&id=118

Stream 1

如何在PHP頁面中打開url以獲取完整的輸出而不進行重定向?

要使用file_get_contents從URL檢索內容,應在php.ini中將allow_url_fopen設置配置為On。

最好使用cURL

$url="http://adfoc.us/1575051";

$ch = curl_init();

$header=array('GET /1575051 HTTP/1.1',
    'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language:en-US,en;q=0.8',
    'Cache-Control:max-age=0',
    'Connection:keep-alive',
    'Host:adfoc.us',
    'User-Agent:Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36',
    );
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );

curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');

curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result=curl_exec($ch);

curl_close($ch);

從這里使用此類httpclient

這個用起來很簡單

include("HttpClient.class.php");

$client = new HttpClient('testbox.elementfx.com');

$data=$client->get('http://testbox.elementfx.com/get-listing.php')

$fulldata=$client->getContent();

或使用include()

像這樣

include ("http://testbox.elementfx.com/get-listing.php"); (not recommended security issues)

查看您的php.ini ,並確保將allow_url_include設置為1。重新啟動HTTPD,完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM