function query($url, $pfields = 0, $cookie = 0)
{
curl_setopt($ch, CURLOPT_HEADER, 1);
if (!empty($pfields))
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pfields);
}
if (!empty($cookie))
{
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING,'gzip');
if (!$login)
{
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
$content = curl_exec($ch);
return $content;
}
$cookie = 'sessionID=3864cab58412ec567b634db3c317898;OAGEO=RU%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C;';
$p = '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++';
$post = 'clientid=23&campaignid=52&bannerid=111&appendsave=1&appendtype=0&append=' . urlencode($p) . '&submitbutton=';
echo query('http://example.com/in.php', $post, $cookie);
This code is returned 417 error(
BUT $p is not usage urlencode but IS OK but +(plus) change for " "(space)
Sooooorry for my very bad english
Try adding this:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
Related
This code not saving access token after verifying that this access token is valid or not instead of that it returns i=1. Eight hours ago this script work fine but it suddenly stop working.
<?php
function get_json($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data);
}
function get_html($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$token2 = $_GET["user"];
session_start();
if(isset($token2)){
if(preg_match("'access_token=(.*?)&expires_in='", $token2, $matches)){
$token = $matches[1];
}else{
$token = $token2;}
$exe = json_decode(get_html("https://graph.facebook.com/app?access_token=".$token ))->id;
$extend = get_html("https://graph.facebook.com/me/permissions?access_token=" . $token);
if($extend == true){
$pos = strpos($extend, "publish_actions");
if ($pos == true) {
$_SESSION['token'] = $token;
$ch = curl_init('http://my site/saver.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "token=".$token);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec ($ch);
curl_close ($ch);
header('Location:index.php');
}
else {
header('Location:index.php?i=1');}
//access token is not valid
}else{
header('Location:index.php?i=4');}
}else{
header('Location:index.php?i=2');}
?>
i maked this function:
function makeRequest($url,$browser,$ip,$cookie = false,$referrer = null)
{
if($referrer==null)
{
$refferer = 'http://google.com';
}
$headers = array();
$headers[] = "HTTP_X_FORWARDED_FOR: ".$ip;
$headers[] = "X_FORWARDED_FOR: ".$ip;
$headers[] = "REMOTE_ADDR:". $ip;
$headers[] = "REFERRER: ".$referrer;
$headers[] = $browser;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
if($cookie!==false)
{
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
}
else
{
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
}
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
if($cookie==false)
{
$return = curl_exec($ch);
}
else
{
$return = 'hidden content';
curl_exec($ch);
}
curl_close($ch);
return $x;
}
But everytime returning the content, if i already set cookie to false.
I don't know how can i do that.
I tried with:
CURLOPT_RETURNTRANSFER,
CURLOPT_VERBOSE,
CURLOPT_HEADER
But nothing...
Thank's (sorry for my eng)
I am trying to send POST data using CURL to an url. This URL is called by an iframe, which is in my application.
<iframe frameborder="0" width="950" height="1000" src="/tools/costs"></iframe>
public function costs()
{
$url = "http://someurl.com/tools/costs";
if($_POST)
{
$fields_str = http_build_query($_POST);
$query = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D',$fields_str);
$realstring = str_replace("%5D", "", str_replace("%5B", "", $query));
// $realstring echo:
var_carrier=3&var_carrier=5&var_carrier=6&var_service=Demurrage+%2F+Storage&var_service=Detention&var_pod=Ancona&var_pod=Antalya&var_pod=Antwerpen
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$realstring);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
}
else
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
curl_close($ch);
$fields_str = "";
}
echo $response;
}
but the $realstring variable is empty when i send it by cURL POSTFIELDS
I have no idea wy!
I am using curl in my application.
My function in DefaultController:
public function actionWebServices()
{
$data = array("account" => "1234", "dob" => "30051987", "site" => "mytestsite.com");
$fields='';
foreach ($data as $key => $value)
{
$fields .= $key . '/' . $value . '/';
}
rtrim($fields, '&');
$u='admin';
$p='admin123';
$url='localhost:83/Working-copy/mysite/ServiceTypeMaster/Test';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERPWD, $u.':'.$p);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
session_write_close();
$result = curl_exec($ch);
curl_close($ch);
session_start();
return $result;
}
In serviceTypeMasterController:
public function actionTest()
{
echo "test";
}
I am calling URL of localhost in curl URL. but curl doesn't give any response. It only gives me only Response Doesn't contain any data.
What is wrong?
Typically, that response is if the page/service does not exist. Are you sure you're running your server on port 83 (and not on default 80) and that the url resolves to your actionTest (instead of test) method?
for some reason , its not collecting all the cookies, its not collecting the password hash or the member id , im not sure why its not setting those since its getting the others, am i doing somthing wrong with my coding, this is my first time using curl
this is the information in the cookie.txt file
<?php
//init curl
function curl_file_get_contents($url){
$username = 'user#hotmail.com';
$password = 'mypass';
$loginUrl = 'http://forums.zybez.net/index.php?app=curseauth&module=global§ion=login';
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=' . $username . '&pass=' . $password);
$store = curl_exec($ch);
curl_setopt($ch, CURLOPT_REFERER, 'http://forums.zybez.net/runescape-2007-prices/282-law+rune');
$content = curl_exec($ch);
curl_close($ch);
file_put_contents('~/download.zip', $content);
$curl = curl_init();
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_REFERER, $loginUrl);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
$contents = curl_exec($curl);
return $contents;
curl_close($curl);
}
function get_input_tags($html){
$post_data = array();
// a new dom object
$dom = new DomDocument;
//load the html into the object
$dom->loadHTML($html);
//discard white space
$dom->preserveWhiteSpace = false;
//all input tags as a list
$input_tags = $dom->getElementsByTagName('input');
//get all rows from the table
for ($i = 0; $i < $input_tags->length; $i++) {
if (is_object($input_tags->item($i))) {
$name = $value = '';
$name_o = $input_tags->item($i)->attributes->getNamedItem('name');
if (is_object($name_o)) {
$name = $name_o->value;
$value_o = $input_tags->item($i)->attributes->getNamedItem('value');
if (is_object($value_o)) {
$value = $input_tags->item($i)->attributes->getNamedItem('value')->value;
}
$post_data[$name] = $value;
}
}
}
return $post_data;
}
/*
Usage
*/
error_reporting(~E_WARNING);
function getauth(){
$html = curl_file_get_contents("http://forums.zybez.net/runescape-2007-prices/282-law+rune");
echo "<pre>";
$auth1 = (get_input_tags($html));
$auth = $auth1["auth"];
print_r($auth1);
}
getauth();
?>