I need to connect to GitHub with Curl using PHP and create a new issue.
I can connect to GitHub and access the 'New Issue' page. However, I cannot POST the Title and Body afterwards. So I do everything but in the last step (ISSUE POST) I encounter the following error.
"What‽ Your browser did something unexpected. Please contact us if the problem persists. "
I don't think there is a problem with cookies
Does anyone have any idea what to do?
require 'simple_html_dom.php';
define('USERNAME', 'username');
define('PASSWORD', 'password');
define('LOGIN_FORM_URL', 'https://github.com/login');
define('LOGIN_ACTION_URL', 'https://github.com/session');
define('ISSUES_FORM_URL', 'https://github.com/bdohyuga/olacakokadar/issues/new/choose');
define('ISSUES_ACTION_URL','https://github.com/bdohyuga/olacakokadar/issues' );
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/80.0.3987.149 Mobile Safari/537.36' );
//curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL,LOGIN_FORM_URL);
$login = curl_exec($ch); // FORM ISTEGI
foreach(str_get_html($login)->find('input') as $element) {
$postValues[$element->name] = $element->value;
}
$postValues['login'] = USERNAME;
$postValues['password'] = PASSWORD;
curl_setopt($ch, CURLOPT_URL,LOGIN_ACTION_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postValues);
$login = curl_exec($ch); // GIRIS ISTEGI
curl_setopt($ch, CURLOPT_URL,ISSUES_FORM_URL);
$login = curl_exec($ch); // NEW ISSUE
//echo $login;
foreach(str_get_html($login)->find('input') as $element) {
$issuesValues[$element->name] = $element->value;
}
$issuesValues['issue[title]'] = "TITLE SUCCESS";
$issuesValues['issue[body]'] = "body success";
curl_setopt($ch, CURLOPT_URL,ISSUES_ACTION_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $issuesValues);
$login = curl_exec($ch); // ISSUES ISTEGI
echo $login;
Related
Can anyone help me? I am tring to hit a website using curl.
My code is as follows:
$data = array(
'utm_source'=>'Google',
'utm_medium'=>'Google',
'utm_campaign'=>'Sales',
'utm_term'=>'united flights tickets'
);
$data = http_build_query($data, '', '&');
$proxies[] = 'user:password#71.6.46.151:443';
$proxies[] = 'user:password#14.102.19.206:61217';
$proxies[] = 'user:password#187.95.230.65:8080';
$url = 'https://www.example.com/index.php?'.$data;
$ch = curl_init();
if (isset($proxy)) { // If the $proxy variable is set, then
curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com');
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_URL, $url);
$results = curl_exec($ch); // Execute a cURL request
if (curl_error($ch)) {
$error_msg = curl_error($ch);
}
$info = curl_getinfo($ch);
curl_close($ch);
print_r($error_msg);
print_r($info);
print_r($results);
It hits the website and also displayed in the Google Analytics account, but the only problem is that the refferer and source showing "direct" in Google Analytics.
If there is any other way to achive this, please tell me.
I am trying log in a website which has security code for 2 days like you see below.
(By the way, I can get security number from html codes of web page.)
First, I have to connect to website and get the code(254), than post username, password and security number. But there is a big problem. I am getting security number and the page is reloading and the code is changing everytime when I try post to webpage this variables.
Here is my PHP code:
<?php
include('simple_html_dom.php');
$url = "http://example.com/index.php";
$useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
$tmpfname = dirname(__FILE__).'/cookies.txt';
$ch = curl_init(); // GET REQUEST
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$str = curl_exec($ch);
echo $str;
curl_close($ch);
preg_match('~<td><img src="number/(.*?).jpg"></td>~', $str, $securityNo); // I am gettin security number
echo $securityNo[1]; // It print true
$username = "USER";
$password = "PASS";
$postfields = array();
$postfields['UserName'] =$username; // Username
$postfields['Password'] = $password; // Password
$postfields['code'] = $securityNo[1]; // Code
$postfields['LOGIN'] = "LOGIN"; // BUTTON
$curl =curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$ret = curl_exec($curl);
curl_close($curl);
echo $ret;
?>
I printed screen both 'echo $str' (get request) and 'echo $ret' (post request) but there is different 2 codes in screen, not same code printed.
I researched on internet too much, but I got nothing. I can't solve this.
Thanks in advance!
I'm trying to login on website http://www.discogs.com using PHP script and cURL.
I need that to get data from https://www.discogs.com/sell/mywants?ev=wsim - it's a list of offers with items added to want-list. From what I found this list is not available in API.
I have problem with logging in using standard cURL request. Here's my code:
$username = 'myuser';
$password = 'mypassword';
$loginUrl = 'https://www.discogs.com/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.urlencode($username).'&password='.urlencode($password));
curl_setopt($ch, CURLOPT_COOKIEJAR, 'c:\cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'c:\tmp.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
return;
} else {
echo "OK";
}
curl_setopt($ch, CURLOPT_URL, 'https://www.discogs.com/sell/mywants?ev=wsim');
$content = curl_exec($ch);
echo $content;
curl_close($ch);
As a result I get login page instead of page with listed offers.
Could you tell me what am I doing wrong?
As I tested, the login page requires posting another field, which is Action.Login in order to make the login request valid.
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username='.urlencode($username).'&password='.urlencode($password).'&Action.Login=');
Hope this helps.
I'm trying to parse a website with curl.
However the first screen is a empty form.
So far I'm getting an error (301-302)
Here is my code:
<?php
$url = "https://www.interiorhealth.ca/HedgehogPortal/?returnUrl=/HedgehogPortal/facility/Table";
$url_redirect = "https://www.interiorhealth.ca/HedgehogPortal/facility/Table";
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36');
define('COOKIE_FILE', 'cookie.txt');
define('FORM_URL', $url);
define('REDIRECT_URL', $url_redirect);
$postValues = array();
//Initiate cURL.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, REDIRECT_URL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postValues));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($curl, CURLOPT_USERAGENT, USER_AGENT);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_REFERER, FORM_URL);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
$server_output = curl_exec($curl);
//Check for errors!
if(curl_errno($curl)){
throw new Exception(curl_error($curl));
} else {
echo $server_output;
}
?>
Any help or pointers would be gladly appreciated.
Thank you!
I'm currently trying to login to LinkedIn, outside of their oAuth system (as it doesn't have the option for a task at hand). I'm not entirely familiar with cURL, so I may have some silly mistake somewhere.
However I don't seem to be having any luck what so ever, even after taking a look at similar questions on stackoverflow but for python. I'm getting the error
"Request Error
We’re sorry, there was a problem with your request. Please make sure you have cookies enabled and try again."
I've fetched the loginCsrfParam and have checked out the postfield sent (it all checks out), I've tried sending the postfields as either an array or as a string like: session_key=".$username."&session_pass...
Here is my php code, any ideas?
<?php
class linkedInLogin {
public function login(){
$username = 'Email Here';
$password = 'Password here';
$csrf = $this->fetchCSRF();
if($csrf == false){
echo 'Error: loginCsrfParam fetching failed.';
return;
}
//login form action url
$url="https://www.linkedin.com/uas/login-submit";
//$postinfo = "session_key=".$username."&session_password=".$password."&loginCsrfParam=".$csrf;
$postfields = array('session_key' => $username, 'session_password' => $password, 'loginCsrfParam' => $csrf);
$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_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //#TODO change back: curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.linkedin.com/uas/login');
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, $postfields);
echo curl_exec($ch);
curl_close($ch);
}
// Fetches the CSRF for login authentication
private function fetchCSRF(){
$url = 'https://linkedin.com/uas/login';
$html = file_get_contents($url);
$precsrf = (int) strpos($html, '<input type="hidden" name="loginCsrfParam" value="');
$postcsrf = (int) strpos($html, '" id="loginCsrfParam-login">');
$length = $postcsrf - $precsrf - 50; // The -50 / + 50 is to correct for: <input type="hidden" name="login...
$csrf = substr($html, $precsrf + 50, $length);
if($csrf == false){
return false;
}
return $csrf;
}
}
Update: I still haven't had any luck with this, although other services don't offer similar functionality that I require.