Url not diplaying using php curl - php

I am trying to display a https url but it is not working.It works for other https websites like facebook,microsoft,google but for this it is not working.I don't know the reason why it is happening like that.Below is the code i have written.
Please help.
<?php
error_reporting(E_ALL);
$url = "https://sgate.bmwgroup.com/login_common.fcc";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
$curl_scraped_page= curl_exec($ch);
if(!$curl_scraped_page)
{
echo "first learn";
}
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
echo $curl_scraped_page;
curl_close($ch);
?>

Related

403 Error with PHP cURL from external website

I am trying to get string from external website but i am getting 403 error. I have tried using custom user agent and same error. Can you please check and help me to get it fixed.
Code :
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$homepage = file_get_contents_curl("https://www.transunion.com/");
echo $homepage;
Help me fix this.

Url not using php curl

I am trying to open a https url but it is not working.It works for other https websites but for this it is not working.I don't know the reason why it is happening like that.Below is the code i have written.
Please help.
<?php
error_reporting(E_ALL);
$url = "https://sgate.bmwgroup.com/login_common.fcc";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt ( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)" );
$curl_scraped_page= curl_exec($ch);
if(!$curl_scraped_page)
{
echo "first learn";
}
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
echo $curl_scraped_page;
curl_close($ch);
?>
good news that page is working, bad news that site is using javascript, and while he doesn't get his scripts, the page is not showing. instead of echo $curl_scraped_page;
try to use:
var_dump(htmlspecialchars($curl_scraped_page));

Login to router using CURL

I am trying to auto login and restart my router automatically using PHP with the help of CURL, but it always return "Protected Object" even the user and password are correct. The script was tested from local host and there is no firewall:
<?php
$host = "192.168.1.250";
$user = "reboot";
$pass = "default";
$timeout = 10;
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, "http://".$host."/restart.html");
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
echo $data; // always return "Protected Object"
?>

Amazon Blocks cURL Request?

I am trying to use php cURL to fetch amazon web page but get
HTTP/1.1 503 Service Temporarily Unavailable instead. Is Amazon blocking cURL?
http://www.amazon.com/gp/offer-listing/B003B7Q5YY/
<?php
function get_html_content($url) {
// fake user agent
$userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
$string = curl_exec($ch);
curl_close($ch);
return $string;
}
echo get_html_content("http://www.amazon.com/gp/offer-listing/B003B7Q5YY");
?>
I use simple
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $offers_page);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$html = curl_exec($ch);
curl_close($ch);
but i have another problem. if you send a lot of queries to amazon - they start send 500 page to you.

PHP CURL Login with cookie

I have a chat service that i would like to make an announcement bot that runs on cron to post daily updates to this chat. The url is http://www6.cbox.ws/box/?boxid=524970&boxtag=7xpsk7&sec=form I have tried various curl examples online but none seem to get the job done. My latest attempt which was a failure.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www6.cbox.ws/box/?boxid=&boxtag=&sec=profile&n=andysmith&k=0000000000000000000000000000000000000000");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www6.cbox.ws/box/?boxid=&boxtag=&sec=profile&n=andysmith&logpword=iloveJD');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cbox.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cbox.txt');
curl_exec($ch);
curl_close($ch);
I just need it to login and post a message.
try with
$result=curl_exec($ch);
//print $result;
if($result === false)
{
echo '<br/>Curl error: '.curl_error($ch);
curl_close($ch);
exit;
}
and see the error
Note: if u r setting 'CURLOPT_REFERER' , u need to set
curl_setopt($ch, CURLOPT_HEADER, true);

Categories