Skip to content

Instantly share code, notes, and snippets.

@azizozbek
Last active December 9, 2017 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azizozbek/90434fa46f09efd42a81d98136590fe5 to your computer and use it in GitHub Desktop.
Save azizozbek/90434fa46f09efd42a81d98136590fe5 to your computer and use it in GitHub Desktop.
<?php
if($_GET){foreach ($_POST as $key => $value) echo htmlspecialchars($key)." = ".htmlspecialchars($value)."\n";} // Controll the Post Fields of target, to be sure if there is hidden values. ( just open the form of the site with ctrl+shift+c and change action="localhost/curl.php" to here )
function get_curl($name, $pass, $loginForm, $page){
$USER_AGENT = 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36'; //browser defination
$COOKIE_FILE = 'cookie.txt'; // create a txt file called cookie.txt
$LOGIN_FORM_URL = $loginForm; // login form
$LOGIN_ACTION_URL = $loginForm; // where login form goes (action=""), if its same, just write $loginForm
$postValues = array(
'username' => $name,
'password' => $pass
);
$curl = curl_init(); // curl start
curl_setopt($curl, CURLOPT_URL, $LOGIN_ACTION_URL); // url define
curl_setopt($curl, CURLOPT_POST, true); // form method = post
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postValues)); //// our postfields values.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // no SSL problem
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // no SSL problem
curl_setopt($curl, CURLOPT_COOKIEJAR, $COOKIE_FILE); // cookie file to write our Session Infos
curl_setopt($curl, CURLOPT_USERAGENT, $USER_AGENT); // wo am i?
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //// give me the result when curl done.
curl_setopt($curl, CURLOPT_REFERER, $LOGIN_FORM_URL); // where we are coming ?
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); // should we follow the link, after curl done
curl_exec($curl); //execute curl
if(curl_errno($curl)){
throw new Exception(curl_error($curl)); // if there is an error, show me
}
curl_setopt($curl, CURLOPT_URL, $page); // which page do you wanna get after login
curl_setopt($curl, CURLOPT_COOKIEJAR, $COOKIE_FILE); // our Session File
curl_setopt($curl, CURLOPT_USERAGENT, $USER_AGENT); //who we are
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // no SSL problem
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // no SSL problem
$get = curl_exec($curl);
switch ($http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) { // success ?
case 200:
return $get;// give me the all content
break;
default:
return "error";
}
curl_close($curl); //curl done
}
$username = ""; // your username
$password = ""; // your password
$formPage = ""; // login form page
$indexseite = ""; //after login which page do we wanna go
$get = get_curl($username, $password, $formPage, $indexseite);
//preg_match('@<title>(.*?)</title>@si', $get, $title); //title
//echo strtoupper($title[1]) . $eol;
echo $get;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment