简体   繁体   中英

How to open url in php without redirect

I need some help with PHP, I want to open the url to get the full output from get-listing.php.

I tried this:

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

It will show me an empty page, but if I use this:

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

It will redirect me to the get-listing.php which I will get the full output.

If I open the get-listing.php url, I will see the full output which will look like this:

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

How do I open the url in my PHP page to get the full output without redirect?

要使用file_get_contents从URL检索内容,应在php.ini中将allow_url_fopen设置配置为On。

You would be best off using 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);

use this class from here httpclient

it is easy to use

include("HttpClient.class.php");

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

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

$fulldata=$client->getContent();

or include using include()

like this

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

Look at your php.ini and make sure allow_url_include is set to 1. Restart HTTPD, done.

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