I try to login on axs.com using PHP curl but my script doesn't work.
I want small help to auth this page via PHP.
Is there error in my code?
$username = 'aUsername';
$password = 'aPassword';
$loginUrl = 'https://www.axs.com/login_check';
/* EDIT EMAIL AND PASSWORD */
$EMAIL = $username;
$PASSWORD = $password;
function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
curl_close($ch);
}
$a = cURL($loginUrl,true,null,"_username=$EMAIL&_password=$PASSWORD");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL($loginUrl,true,null,"_username=$EMAIL&_password=$PASSWORD");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
$cookie.=$d[1][$i].";";
/*
NOW TO JUST OPEN ANOTHER URL EDIT THE FIRST ARGUMENT OF THE FOLLOWING FUNCTION.
TO SEND SOME DATA EDIT THE LAST ARGUMENT.
*/
echo cURL("http://www.axs.com/",null,$cookie,null);
?>
Is this possible on this web site?
Related
I am trying to get some values from similarweb using curls and simple_html_dom, but i can't grab only the value that i want. It gives me outpt all the page.
I am using the code bellow (this code works for other sites).
<?php
header('Content-Type: text/html; charset=utf-8');
require_once ('url_to_absolute/simple_html_dom.php');
$url = 'https://www.similarweb.com/website/bbc.com/#overview';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
$result = curl_exec($curl);
curl_close($curl);
$html = new simple_html_dom();
$html->load_file($result);
$div = $html->find('div.wa-rank-list__value',0)->outertext;
echo $div;
?>
I am trying to capture the value below:
Please give me a help.
<?php
header('Content-Type: text/html; charset=utf-8');
$url = 'http://www.similarweb.com/website/bbc.com/#overview';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
$result = curl_exec($curl);
curl_close($curl);
preg_match_all('#<p class="wa-rank-list__value"><small>#</small>(.*?)</p>#si',$result,$r);
echo $r[1][1];
?>
I need to convert this PHP cURL request to JavaScript. I'm not exactly sure how to go about doing it.
I basically need to make this request be client sided instead of server sided.
function createSite($template_id) {
//create array with data
$data = array("template_id"=>$template_id);
//turn data into json to pass via cURL
$data = json_encode($data);
print $data;
//Set cURL parameters
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,
CURLOPT_URL,'https://api.duda.co/api/sites/multiscreen/create');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, API_USER.':'.API_PASS);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//execute cURL call and get template_idte data
$output = curl_exec($ch);
//check for errors in cURL
if(curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
//decode result
$output = json_decode($output);
//return unique site_name
return $output->site_name;
A have cURL login to a network router which is triggered by ajax. But I need to keep the connection alive until an xhr request is finished on success.
Is this somehow possible?
To clarify here is what I want to do, here is my Ajax function for the login:
function logintorouter(){
$.ajax({
type: 'GET',
dataType:"text",
url: 'login.php'
}).done(function(data){
if(data.includes('WiFi')){
setWiFichannel(); /*Wait for this function to finish before closing cURL connection */
}else{
alert('something went wrong, try again later!');
}
}).fail(function(data){
alert('can not connect to router');
});
}
and my login.php looks like this now:
<?php
function openRouter(){
$username = 'admin';
$password = 'pass';
$url="http://10.1.10.1/login/Auth";
$postinfo = "username=".$username."&password=".$password;
$cookie_file_path = "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "http://10.1.10.1/main.html#WiFi");
$mainPage = curl_exec($ch);
curl_close($ch);
/*As you can see I close the connection here so the setWiFichannel() will fail
but I don't want to keep the connection alive forever*/
return $mainPage;
}
echo openRouter();
?>
I have tried file_get_content and curl but both don't seem to work on the website. I have used both on previous projects.
Website: https://colruyt.collectandgo.be/cogo/nl/zoeken?z=5030
Anyone has a working solution. Been looking and testing for hours now :).
Curl also does not seem to work.
HTTP/1.1 200 OK Content-Length: 5395 Pragma: no-cache Cache-Control: no-cache Content-Type: text/html
Redirects to my own main domain name
I used this code:
<?php
function geturl($url){
(function_exists('curl_init')) ? '' : die('cURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini');
$cookie = tempnam ("/tmp", "CURLCOOKIE");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; CrawlBot/1.0.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); # required for https urls
curl_setopt($ch, CURLOPT_MAXREDIRS, 15);
$html = curl_exec($ch);
$status = curl_getinfo($ch);
curl_close($ch);
if($status['http_code']!=200){
if($status['http_code'] == 301 || $status['http_code'] == 302) {
list($header) = explode("\r\n\r\n", $html, 2);
$matches = array();
preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
$url = trim(str_replace($matches[1],"",$matches[0]));
$url_parsed = parse_url($url);
return (isset($url_parsed))? geturl($url):'';
}
}
return $html;
}
echo geturl("https://colruyt.collectandgo.be/cogo/nl/zoeken?z=5030");
?>
Take a look at request
var request = require('request');
request('https://colruyt.collectandgo.be/cogo/nl/zoeken?z=5030', function (error, response, body) {
console.log(body)
})
This prints the body of the response.
i am trying to send an array of JSON objects to
PHP server using an hidden field
but all i am getting in the server is just a string
this is my javascript
function CreateArrayOfJSON()
{
var all_childrens = $('#form_div').find('*');//get all root element childrens
var form_elements = {
elements: []
};
for(var i=0;i<all_childrens.length;i++)
{
var id='#'+$(all_childrens[i]).attr('id'); //get id
var style_attr=$(all_childrens[i]).attr('style'); //get style inline
var classes=$(all_childrens[i]).attr("class");
form_elements.elements.push
({
"id" : id,
"style_attr" :style_attr,
"classes" :classes
});
}
document.getElementById('form_elements_array').value=form_elements;//fill hidden field
}
this is my PHP:
this will return Object object (as in the picture above)
$form_elements=$_POST['form_elements_array'];
this will return null
$form_elements=json_decode($_POST['form_elements_array']);
any ideas ?
thank you
document.getElementById('form_elements_array').value=JSON.stringify(form_elements);
can you paste the output string ?
or alternatively
You can use Curl for the same
$url = "URL Where you want to send data";
$ch = curl_init();
$attachment = array(
'name' => 'Your first field',
'link' => 'Second Field',
'description' => 'description here',
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result = curl_exec($ch);
curl_close($ch);
now php code on the receiver page
can you paste the output string ?
or alternatively
You can use Curl for the same
$url = "URL Where you want to send data";
$ch = curl_init();
$attachment = array(
'name' => 'Your first field',
'link' => 'Second Field',
'description' => 'description here',
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result = curl_exec($ch);
curl_close($ch);
now php code on the receiver page
echo $_POST['name']; // get your data with POST method