YouTube API implementation with SimpleXML no longer working - php

I had a website that pulled videos from a user's account using a public XML feed. The feed's URL is:
https://gdata.youtube.com/feeds/api/users/USERNAME/uploads
Where USERNAME is dynamically assigned via a PHP variable. The code to hit this URL and grab the contents is:
$file = file_get_contents('https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads');
$xml = simplexml_load_file($file);
However, this is now throwing a weird error:
Warning: file_get_contents() [function.file-get-contents]: Couldn't
resolve host name in /home/dpw/public_html/inc/modules/youtube.php on
line 46
Warning:
file_get_contents(https://gdata.youtube.com/feeds/api/users/dpwrestling/uploads)
[function.file-get-contents]: failed to open stream: operation failed
in /home/dpw/public_html/inc/modules/youtube.php on line 46
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O
warning : failed to load external entity "" in
/home/dpw/public_html/inc/modules/youtube.php on line 47
Warning: Invalid argument supplied for foreach() in
/home/dpw/public_html/inc/modules/youtube.php on line 49
I'm not sure what the problem is, as visiting the URL in my web browser returns the XML fine. Why is my PHP script now having trouble retrieving it?
For the record, the allow_url_fopen is still enabled in my hosting environment as I checked using echo ini_get('allow_url_fopen'), which printed 1.

Related

Read html data from given url

I have the below code that tries to pull text from an url.
include_once("html_parser/simple_html_dom.php");
$html=file_get_html("http://82.77.18.164:8080/Iphone/get_puncte.php");
print_r($html);
echo file_get_contents("http://82.77.18.164:8080/Iphone/get_puncte.php");
echo stream_get_contents(fopen('http://82.77.18.164:8080/Iphone/get_puncte.php', "r"));
If i access the url in my browser it works fine, but in when i access the php file with the code above i receive the below erros.
PHP Warning: file_get_contents(http://82.77.18.164:8080/Iphone/get_puncte.php): failed to open stream: Connection refused
PHP Warning: stream_get_contents() expects parameter 1 to be resource, boolean given in /home/xxxxx/public_html/test.php on line 9
Any idea ?
Some servers deny using an IP address instead would recommend to use curl

Trying to access url that returns json results in connection reset by peer error

My php web app is trying to access another URL on the same site that returns a json payload. My web app is using file_get_contents() on the url that returns the json and then does something with it.
I have tried using curl instead of file_get_contents, but i get the same errors which are:
A PHP Error was encountered
Severity: Notice
Message: file_get_contents(): send of 24 bytes failed with errno=104 Connection reset by peer
Filename: xxxxxx.php
Line Number: 46
And
A PHP Error was encountered
Severity: Notice
Message: file_get_contents(): send of 2 bytes failed with errno=32 Broken pipe
Filename: xxxx.php
Line Number: 46
Now, this worked on the previous server the web app was hosted on i'm told and this is now on some shared hosting.
So, to recap, when you visit the url http://example.com/getjson it runs some php that does:
$foo = file_get_contents('http://example.com/twitter.json/?user_id=xxxxxx&count=500&include_rts=1&page=1&include_entities=5');
If i visit http://example.com/twitter.json/?user_id=xxxxxx&count=500&include_rts=1&page=1&include_entities=5 in my browser i see the json, if i try and get it with php, i get the errors above.
I just can't think what to try next!
Any help gratefully received!

Warning: include(lang/1%00'=1.php): failed to open stream: No such file or directory in C:\xampplite\security\htdocs\index.php on line 12

Getting a really strange error here. I'm developing a WordPress website locally via ServerPress (called localhost.dev). Everything works fine except for the url localhost.dev/security. I'm trying to give a page this URL, but when I do, the error below shows up on the page. I've never encountered this before, does anyone have an idea how I can fix this?
( ! ) Warning: include(lang/1%00'=1.php): failed to open stream: No such file or directory in C:\xampplite\security\htdocs\index.php on line 12
( ! ) Warning: include(): Failed opening 'lang/1%00'=1.php' for inclusion (include_path='.;C:\xampplite\php\PEAR') in C:\xampplite\security\htdocs\index.php on line 12
Image of error
Seems that someone had the same problem :
In file lang.tmp write only en set up english language and all will be correct.
https://community.apachefriends.org/f/viewtopic.php?t=68507&p=242365

File_get_content works on the local server, but not hosted on server

I am working on download functionality in code-igniter as i am newbie to the framework
I am facing problem with this functionality which is working fine on localhost but failed to work on server..
As describing my problem
Here is the download function in my controller
public function download()
{
$uri=$this->uri->segment(2);
$check=array();
$check['q_id']=$uri;
$img= $this->prototype_model->get_data($check,'orders');//getting data from db
$imgname=$img['stl_image'];//stores the image name from result array
$data = file_get_contents(base_url()."assets/upload_img/".$imgname);// Read the file's contents
$name = $imgname;//name to download file
force_download($name, $data);
}
As i searched on SO for solution ,i found that allow_url_fopen = on and i checked on my server about this ,it was fine.
I am able to get the data based on uri segment, but file_get_content not taking the image name and the server returns some errors as follows
Error 1
Severity: Notice
Message: file_get_contents() [function.file-get-contents]: send of 30 bytes failed with errno=104 Connection reset by peer
Filename: controllers/prototype.php
Line Number: 796
Error-2
Severity: Notice
Message: file_get_contents() [function.file-get-contents]: send of 2 bytes failed with errno=32 Broken pipe
Filename: controllers/prototype.php
Line Number: 796
Any suggestions will be greatly appreciated

Error while invoking REST service

I am facing a strange problem. I am trying to integrate a REST api in phonegap application.
When I request the url say http://myserver/index.php?m=login via a rest client in my browser it works fine.
But when I invoke it via jQuery ajax it returns the following error:
Warning:
include(C:/Domains/my-portal.org/httpdocs/mmode/template/mobile/index.php)
[function.include]: failed to open stream: No such file or directory
in C:\Domains\my-portal.org\httpdocs\mmode\index.php on line 13
Warning: include(C:/Domains/my-portal.org/httpdocs/mmode/template/mobile/index.php)
[function.include]: failed to open stream: No such file or directory
in C:\Domains\my-portal.org\httpdocs\mmode\index.php on line 13
Warning: include() [function.include]: Failed opening 'C:/Domains/myportal.org/httpdocs/mmode/template/mobile/index.php' for inclusion (include_path='.;./includes;./pear;C:\PHP\includes') in C:\Domains\my-portal.org\httpdocs\mmode\index.php on line 13
Now the problem is not cross-domain scripting because the response header returns "Access-Control-Allow-Origin: *". And I have also white-listed the domain in cordova settings.
Can anyone please guide me what could be the problem here?

Categories