cURL Authentication Issue - php

below is the code that I try to login on the site. I do not know what does not work, the site probably changed something and that I do not work for me. I have no idea what could be.
$var = file_get_contents("http://www.dauanunt.ro/cont/login");
$q = explode("name=\"q\" value=\"",$var);
$q = explode("\" />",$q[1]);
$q = $q[0];
$ga_bi['a'] = 'login';
$ga_bi['q'] = $q;
$ga_bi['h'] = '';
$ga_bi['u'] = 'gabrielaromania66#gmail.com';
$ga_bi['p'] = 'testing';
$ga_bi['r'] = '1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.dauanunt.ro/cont/login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, "http://www.dauanunt.ro");
curl_setopt($ch, CURLOPT_POSTFIELDS, $ga_bi);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

I don't think there's any coding error. It looks like the website you are trying to login is adding extra steps during the login.
http://www.dauanunt.ro/c/login5.js

Related

file_get_contents equivalent of curl function

I have following curl program which is working fine.
$data="var1=$var1&var2=$var2";
$ch = curl_init("http://www.website.asmx/FetchData");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
I tried following code to get same data using file_get_contents but it returns false.
$data="var1=$var1&var2=$var2";
$result = file_get_contents("http://www.website.asmx/FetchData?=".$data);
var_dump($result);
exit();
What code will be equivalent to above curl program?
Notice the = at the End of FetchData in:
$result = json_decode(file_get_contents("http://www.website.asmx/FetchData?=".$data));
This should rather read:
//WITHOUT THE EQUAL SIGN AFTER FetchData...
$result = json_decode(file_get_contents("http://www.website.asmx/FetchData?".$data));

send inline query result error (Telegram)

I wanted to make an inline bot! and when i do this:
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('inline_query_id' => $data['inline_query_id'], 'results' => json_encode($data['results'])));
$output = curl_exec($ch);
return $output;
}
It wont work, the error (with or without the header): {"ok":false,"error_code":400,"description":"[Error]: Bad request: Field \"message_text\" must be of type String"}
but when I do it like this:
function sendResponse($url, $data){
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_URL, $url.'?inline_query_id='.rawurlencode($data['inline_query_id']).'&results='.rawurlencode(json_encode($data['results'])));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $q);
$output = curl_exec($ch);
return $output;
}
It works ! the problem is the second method request URI will be too large so I cannot use it!
Any way I can send these data is okay with me! thanks!
and the code for making $data is here:
$result = connectWebsite(SITE_SEARCH_URL, urlencode($update['inline_query']['query']));
$result = json_decode($result);
$output = array();
$output['inline_query_id'] = $update['inline_query']['id'];
$i = 0;
foreach($result as $post){
$data = array();
$data['type'] = 'article';
$data['id'] = strval($post->ID);
$data['title'] = '('.$post->atypes.') '.$post->title;
if(strlen($post->content) > 2100)
$tmp = substr($post->content, 0, 2096).'...';
$data['message_text'] = '<b>'.$post->title.'</b>'.ucwords($post->genre, ',').$tmp;
$data['parse_mode'] = 'HTML';
if(strlen($post->content) > 200)
$tmp = substr($post->content, 0, 196).'...';
//$data['description'] = ucwords($post->genre, ',').' | '.$tmp;
$output['results'][$i] = $data;
$i++;
if($i == MAX_RESULTS)
break;
}
sendResponse(API_URL.'answerInlineQuery', $output);
It might help someone so I'll answer it myself.
the problem was the UTF-8 encoding
I replaced substr with mb_substr
besides at the first line I'v added this: mb_internal_encoding("UTF-8")
and ... the problem was solved. now I can send my inline query results (or any other command) without the URL length problem
Thanks everyone for your help

How to enable disable motion detection DCS-933L(D-link Cam) with Curl?

I try this code in php but I don't solve!
$s = $motion = 1;
$camIp = "192.168.1.124";
$camUser = "admin";
$camPass = "gatelliHome";
$params = "ReplySuccessPage=motion.htm&ReplyErrorPage=motion.htm&MotionDetectionEnable=$motion&MotionDetectionSensitivity=85&ConfigSystemMotion=Save";
curl_setopt($ch, CURLOPT_URL, "http://$camIp/motion.cgi");
curl_setopt($ch, CURLOPT_USERPWD, "$camUser:$camPass");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_exec($ch);
curl_close($ch);
I isn't certain the $url and $params are correct!
Can you help me?

cURL with PHP - HTTP cURL to HTTPS

I have the following bit of PHP, it works locally (via apache and localhost) but not on my hosting - $response is always empty:
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$api_key = 'my_api_key';
$randomString = generateRandomString(10);
$endLabel = sha1(md5($randomString));
$user_id = $endLabel;
$amount_doge = '5';
$url = "https://dogeapi.com/wow/?api_key=".$api_key."&a=get_new_address&address_label=".$user_id;
$response = get_data($url);
I wondered if this could be because I'm hosted on HTTP (no SSL option) and I'm calling a HTTPS domain? If so, is there a way around this? I've tried curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); but it doesn't seem to do anything :(
try to use echo curl_error($ch) after $data = curl_exec($ch); to see what curl says
it wil lreport you what happened

Curl login Joomla 1.6/3.0

I am trying to login Joomla 1.6/3.0 by curl in PHP but not success.
I had try method from joomla 1.5
$uname = "id";
$upswd = "pswd";
$url = "http://www.somewebpage.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, FALSE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}
// POST fields
$postfields = array();
$postfields['username'] = urlencode($uname);
$postfields['passwd'] = urlencode($upswd);
$postfields['lang'] = '';
$postfields['option'] = 'com_login';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
But it 's show forbidden
Joomla! normally from the web browser will send a token, to make sure the form was posted from a browser (and not from somewhere outside, like you are trying to do).
If it's not posted from a browser, an error like 'The most recent request was denied because it contained an invalid security token. Please refresh the page and try again.'
You may want to look for an autentication plugin that supports what you are trying to do. For example the Autologin plugin.

Categories