PHP url execute - php

I want to update icecast server metadata info, everything works great if I enter it manually into the browser like this:
http://IPADDRESS:PORT/admin/metadata?mount=/live&mode=updinfo&song=ARTIST+SONG+NAME
I get XML response that metadata is successfully updated and it really is if I check live stream (even the iTunes pops out with the song info).
The problem is that I made a php script that should using cURL execute this same URL but I tried numeruos ways and solutions and non of them works. Can anyone help me? How can I execute this URL in the php script?
Thank you!
This is the code in my php that should execute the URL to update metadata but it does not work:
$url = "http://IPADDRESS:PORT/admin/metadata?mount=/live&mode=updinfo&song=".urlencode($params)."";
file_put_contents($file2, $url);
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
var_dump($result);
I even created help so that URL gets saved in .txt file and it gets generated OK. If I copy it and manually enter it in browser metadata gets changed, but automatically trough php script it won't. I also tried with http authentication for icecast and won't work, when I'm entering URL manually I don't need to authenticate for changing metadata.
I really don't know what else to do.
Thank you in advance for any help!

Your script does not have the permission of changing meta data of your Icecast Radio because it does NOT have any username and password. You can make the URL query work in your browser because you simply give username and password before. You can send username and password using CURLOPT_USERPWD
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);

Related

SMS url not working with file operation

My question is, i'm using - $url = http://sms.emefocus.com/sendsms.jsp?user="$uname"&password="$pwd"&mobiles="$mobiil_no"&sms="$msg"&senderid="$sender_id"; $ret = file($url);- url to send sms to users from user panel and i'm using FILE operation to execute this url as mentioned above.
After executing this when i'm trying to print $ret, its giving me status true and generating message id and sending id.
But its not getting delivered to user....??
When same url i'm executing in browser as $url = http://sms.emefocus.com/sendsms.jsp?user="$uname"&password="$pwd"&mobiles=98xxxxxx02&sms=Hi..&senderid="$sender_id"
its getting delivered immediately..??
can anyone help me out..?? Thanks in advance..
It is possible that this SMS service needs to think a browser and not a bot is executing the request, or there is some "protection" we don't know about. Is there any documentation regarding this particular service ? Is it intended to be used like you're trying to do?
You can try with CURL and see if the behaviour is still the same:
<?php
// create curl resource
$ch = curl_init();
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
// set url
curl_setopt($ch, CURLOPT_URL, "example.com");
// Fake real browser
curl_setopt($curl, CURLOPT_USERAGENT, $agent);
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$ret = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
?>
Does it help?

login with curl

I would like to download a book from google books (which I bought regularly) to read it offline (unfortunately this option is not available for my book).
I would like to create me a script that I pull out the pages and then save them in pdf...
I do not think there is anything illegal because I paid ..
I tried using curl, but the page you saw was not authenticated.
I wrote then:
function leggiUrl($url,$data){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
$page=leggiUrl("https://www.google.com/accounts/ServiceLoginAuth", array("Email" => "mia_mail#gmail.com", "Passwd" => "miapassword"));
echo $page;
unfortunately shows me the login page of google ... because it does not log in?
If you look at the source of https://www.google.com/accounts/ServiceLoginAuth you will see a bunch of hidden fields. Google is expecting these fields in order to allow the login. You need to look at using Oauth 2 method of logging into Google, a straight POST won't do it:
https://developers.google.com/accounts/docs/OAuth2

Php CURL automatic Login

This is my first question on this forum but it helped me before by finding answers on it. So I am trying to login automatically to my account using PHP and CURL.
I am new to PHP but until now whenever I needed to connect to a webpage, do a post or a get or follow a redirect everything worked.
The problem is that the account that I am trying to login has a user/password page followed by a memorable word page in which I have to enter some characters from my memorable word.
Now I manage to pass the first page and getting the second page where I have to enter the memorable word characters but when I am trying to do that (so the second post) is not working - I am redirected to the login again.
Now I tried to investigate to see what is the problem but still I am not sure why is not working. I observed that a JSESSIONID is passed by the server in normal login which is the same, while when I run my script the JSESSIONID changes. I am using:
curl_setopt($this->curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($this->curl, CURLOPT_COOKIEJAR, 'cookie.txt');
But when I check the file it's empty and it hasn't been modified since was created. Amd yes the file can be written (it has 777 rights).
I don't know if this is the problem or something else but I looked for answer and I tried different things and nothing worked. So any ideas would be appreciated.
Thank you
Here is an example that I can confirm works. It shows you the full path of the cookieJar file and gets the full path from the script's execution location, so it should work on most OSes.
<?PHP
$cookiepath = __DIR__.DIRECTORY_SEPARATOR.'cookieJar.txt';
echo "Saving cookies to: $cookiepath\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.google.com");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
curl_setopt($ch, CURLOPT_HEADER ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$data = curl_exec($ch);
?>

Cannot get XML output through cURL

I am using PHP cURL to fetch XML output from a URL. Here is what my code looks like:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mydomain.com?querystring');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$store = curl_exec($ch);
echo $store;
curl_close($ch);
But, instead of returning the XML it just shows my 404 error page. If I type the URL http://www.mydomain.com?querystring in the web browser I can see the XML in the browser.
What am I missing here? :(
Thanks.
Some website owners check for the existence of certain things to make sure the request comes from a web browser and not a bot (or cURL). You should try adding curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'); and see if that fixes the problem. That will send a user-agent string. The site may also check for the existence of cookies or other things.
To output the XML in a web-page, you'll need to use htmlentities(). You might want to wrap it inside a HTML <pre> element as well.

php: Get url content (json) with cURL

I want to access https://graph.facebook.com/19165649929?fields=name (obviously it's also accessable with "http") with cURL to get the file's content, more specific: I need the "name" (it's json).
Since allow_url_fopen is disabled on my webserver, I can't use get_file_contents! So I tried it this way:
<?php
$page = 'http://graph.facebook.com/19165649929?fields=name';
$ch = curl_init();
//$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
//curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
With that code I get a blank page! When I use another page, like http://www.google.com it works like a charm (I get the page's content). I guess facebook is checking something I don't know... What can it be? How can I make the code work? Thanks!
did you double post this here?
php: Get html source code with cURL
however in the thread above we found your problem beeing unable to resolve the host and this was the solution:
//$url = "https://graph.facebook.com/19165649929?fields=name";
$url = "https://66.220.146.224/19165649929?fields=name";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: graph.facebook.com'));
$output = curl_exec($ch);
curl_close($ch);
Note that the Facebook Graph API requires authentication before you can view any of these pages.
You basically got two options for this. Either you login as an application (you've registered before) or as a user. See the api documentation to find out how this works.
My recommendation for you is to use the official PHP-SDK. You'll find it here. It does all the session and cURL magic for you and is very easy to use. Take the examples which are included in the package and start to experiment.
Good luck.

Categories