如何在没有重定向的情况下在php中打开url

时间:2014-03-23 16:30:18

标签: php

我需要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页面中打开网址以获得没有重定向的完整输出?

3 个答案:

答案 0 :(得分:0)

使用file_get_contents从url检索内容,allow_url_fopen设置 应该在php.ini中配置为On

答案 1 :(得分:0)

你最好使用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);

答案 2 :(得分:-1)

从这里使用此课程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,完成。