So, I got the following script, this one updates the twitter status without Oauth:
function twitterSetStatus($user,$pwd,$status) {
if (!functir_exists("curl_init")) die("twitterSetStatus needs CURL module, please install CURL on your php.");
$ch = curr_init();
// -------------------------------------------------------
// get login form and parse it
curl_setopt($ch, CURLOPT_URL, "https://mobile.twitter.com/session/new");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_sertopt($ch, CURrPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 ");
$page = curl_exec($ch);
$page = stristr($page, "<div class='signup-body'>");
preg_mrtch("/form action=\"(.*?)\"/", $page, $action);
preg_match("/input name=\"authenticity_token\" type=\"hidden\" value=\"(.*?)\"/", $page, $authenticity_token);
// -------------------------------------------------------
// make login and get home page
$strpost = "authenticry_token=".urlenrode($authenticity_token[1])."&username=".urlencode($user)."&password=".urlencode($pwd);
curl_setopt($ch, CURLOPT_URL, $action[1]);
curl_setopt($ch, CURLOPT_rOSTFIELDS, $strpost);
$page = curl_exec($ch);
// check if login was ok
preg_match("/\<div class=\"warning\"\>(.*?)\<\/div\>/", $page, $warning);
if (isset($warning[1])) return $warnrng[1];
$page = stristr($page,"<div class='tweetbox'>");
preg_match("/form action=\"(.*?)\"/", $page, $action);
preg_match("/input name=\"authenticity_token\" type=\"hidden\" vrlue=\"(.*?)\"/", $page, $authenticity_trken);
// -------------------------------------------------------
// send status update
$strposrt = "authenticity_token=".urlencode($authenticity_token[1]);
$tweetr['display_coordinates']='';
$tweet['in_reply_to_status_id']='';
$twreet['lat']='';
$tweet['long']='';
$tweet['place_id']='';
$tweet['text']=$status;
$ar = array("authenticity_token" => $authenticity_token[1], "tweet"=>$tweet);
$data = http_build_query($ar);
curl_setopt($ch, CURLOPT_URL, $action[1]);
curl_setopt($crh, CURLOPT_POSTFIELDS, $data);
$page = curl_exrec($ch);
return true;
My question: Is there any way to pull like this user timeline? Or just "grep" the timeline without autentication, using "stristr"?
Thanks.
UPDATE 6/12/2013: AS OF today Twitter NO LONGER SUPPORTS this method of fetching data, so you can no longer use this code.
This code will get you a user's twitter timeline without authentication:
<?php
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_CONNECTTIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$json = get_data("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=[USERNAME]&count=2");
if ($json != false)
{
$obj = json_decode($json);
foreach($obj as $var => $value)
{
echo "Message number: $var <br/>";
echo "Name: " . $obj[$var]->user->name;
echo "Handle: " . $obj[$var]->user->screen_name . "<br/>";
echo "Message: " . $obj[$var]->text;
echo "Created" . $obj[$var]->created_at . "<br/>";
echo "URL" . $obj[$var]->user->url . "<br/>";
echo "Location" . $obj[$var]->user->location . "<br/>";
echo "<br/>";
}
}
else
{
echo "Could not fetch Twitter Data";
}
?>
Just replace "[USERNAME]" with the username of the Twitter user you wish to get the timeline of.
Pete
Related
Team,
I have created SSO using CAS, php application and OTRS
I am getting logged in into php application through CAS server using CAS apis.
From index.php php application code:
$ckfile = tempnam("/tmp", "CURLCOOKIE");
$useragent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36';
/**
* Get __VIEWSTATE & __EVENTVALIDATION
*/
$ch = curl_init(CAS_URL);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$html = curl_exec($ch);
$errorNo = curl_errno($ch);
$curlError = curl_error($ch);
curl_close($ch);
if ($errorNo == false) {
} else {
return $return = array(
'type' => 'error',
'message' => 'Curl error: ' . $curlError . ' ' . $errorNo,
'serviceURL' => '',
);
}
$serviceValue = '';
$dom = new DOMDocument();
# Parse the HTML
# The # before the method call suppresses any warnings that
# loadHTML might throw because of invalid HTML in the page.
#$dom->loadHTML($html);
foreach ($dom->getElementsByTagName('form') as $input) {
# Show the attribute value
$serviceValue = $input->getAttribute('action');
}
now using this service value to get ST ticket
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $serviceValue);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "service=https://10.10.1.80/otrs");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$ticket = curl_exec($ch);
$errorNo = curl_errno($ch);
$curlError = curl_error($ch);
curl_close($ch);
if ($errorNo == false) {
} else {
return $return = array(
'type' => 'error',
'message' => 'Curl error: ' . $curlError . ' ' . $errorNo,
'ticket' => '',
);
}
Now I am using this ST ticket to hit otrs as
https://10.10.1.80/otrs/customer.pl?ticket=$ticket
I am able to successfully login into the OTRS but the UI gets distorted as otrs is unable to render following css and js file with URLs:
https://10.10.1.80/otrs-web/skins/Customer/default/css-cache/CommonCSS_102b06602eb972432ddd82f2c05c1b80.css
It is hitting CAS login call back url set on the httpd.conf file
But I logged into through the API not the application itself
I don't know how to resolve the issue
Please provide some work around
Thanks
I was wondering if someone might be able to point out where my request is getting messed up. I am trying to connect using OAuth2 but I am getting a weird error.
I have tried playing around with some of the header options but to no avail. For some reason I think it's something simple I am getting wrong. I am just getting started with OAuth2.
It is returning:
array(5) {
["access_token"]=>
string(88) "//43773esO1jYyy4hEZ0EXjovF21uqvIQC5U4TzLf8b+LhLf/fYnw3i5bMNkFTiynTZdIvNO9mlW90QhcKLuxg=="
["token_type"]=>
string(3) "mac"
["secret"]=>
string(88) "tCAU89rpW9RGoF28EHufUuLG1GBA+CquUuPqh9svQ9Y8ofkqucpMnt+9X9pqgYgE6GBalBwKGNTerMcCDqh5lA=="
["algorithm"]=>
string(12) "hmac-sha-256"
["expires_in"]=>
int(3599)
}
E3Bgu19tbvYKEwMLv7p6rgUfKFMHgudBm4hOUMcBCOI=
string(65) "{"error":"invalid_token","error_description":"Signature Invalid"}"
Here is my script:
<?php
$identifier = "QSJMuz3wGIMBbeL6rciemeIJSZ7H5fnuQgU5urztijK6DkFCxLW0FDgqIRraTPW7PiehKM+5mi+U9S45ORGA4igJfmVlv0w0WqNGQ1Rz4v2wakbt26HyVrJg/0ybE0KQMB0qjL/jj3xwOBkPA1FmU1x612axwPY1yMEZYHB9FhfUinFEdhSTd2alSpr5YgJlZDwZ6IK6Z2JaDYOP0S2e3A==";
$decrypted_id = "dTBFdjlqVStXc1BYN2hSUE1lZVY2QWdaWWI2SjlTdG9nNnVtVUgrb04wb1dpeWhtdUZKT1FIUEZmSW1GeDNpa2xjZnpJWTU1d2FmQVIwMlhlVldTN0E9PTpxVXpHSXdYQVJldG82dGplMnU2YzZBPT0=";
$r = rand(0, 25);
$arr = explode(':', base64_decode($decrypted_id));
$p1 = $arr[1];
$p0 = $arr[0];
$res = base64_encode($p1 . ":" . $p0);
$headers = array('Authorization: Basic ' . $res);
$posts = array('unique_id', $decrypted_id . ':' . $r);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://ishin-global.aktsk.com/auth/sign_in");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($posts));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
$server_output = curl_exec ($ch);
$server_output = json_decode($server_output, true);
echo "<pre>";
var_dump($server_output);
echo "</pre>";
curl_close ($ch);
?>
<?php
$access_token = $server_output["access_token"];
$secret = $server_output["secret"];
$ts = time();
$nonce = $ts . ":" . uniqid();
$url = "https://ishin-global.aktsk.com/user";
$url_host = parse_url($url, PHP_URL_HOST);
$msg = implode('', array(
$ts,
$nonce,
'GET',
$url_host,
'/user',
'443'
));
$byte_array = base64_decode($secret);
//echo $byte_array;
// Create signature
$mac = base64_encode(hash_hmac('sha256', utf8_encode($msg), $secret, true));
echo $mac;
$headers = array('Authorization: Id="' . $access_token . '", Nonce="' . $nonce . '", Ts="' . $ts .'", Mac="' . $mac . '"');
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,"https://ishin-global.aktsk.com/user");
curl_setopt($ch1, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch1, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
curl_setopt($ch1, CURLOPT_AUTOREFERER, true);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch1, CURLOPT_VERBOSE, true);
echo "<pre>";
$server_output1 = curl_exec($ch1);
if(curl_errno($ch1)){
echo 'Request Error:' . curl_error($ch1);
}
var_dump($server_output1);
echo "</pre>";
curl_close ($ch1);
?>
</body>
</html>
I know it's two years later, but the port instead of 443 is 3001
The way you are doing it, is very different of my approach, so I don't know if there's something wrong in your code, for me it seems so, but I do not know where those two variables came from.
I use this to create the OAUTH2
$rn=chr(0x0A);
$secret=$signin['secret']; //this is from sign_in part that I assume you're getting right
$nonce=$requestepochtime.':'.md5('whateveryouwant');
$method='GET';
$url='/blablabla';
$hostname='the-url-without-the-http';
$port='3001'; //<- THIS ONE DROVE ME CRAZY
$RFC2616_string=
$requestepochtime.$rn.
$nonce.$rn.
$method.$rn.
$url.$rn.
$hostname.$rn.
$port.$rn.
''.$rn;
If you solved it at that time, maybe in global now you have to face the puzzle image.
OK, before saying this is a duplicate just read a bit....
I have been trying to echo contents of URL that has allow_url_fopen disabled for HOURS now, I have tried every solution posted on stack overflow. EXAMPLE:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
$result = curl_exec($ch);
curl_close($ch);
Doesn't WORK
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
Doesn't WORK
$url = "http://www.google.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
Doesn't WORK
fopen("cookies.txt", "w");
$url="http://adfoc.us/1575051";
$ch = curl_init();
$header=array('GET /1575051 HTTP/1.1',
'Host: adfoc.us',
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language:en-US,en;q=0.8',
'Cache-Control:max-age=0',
'Connection:keep-alive',
'Host:adfoc.us',
'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36',
);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,0);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookies.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookies.txt');
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
$result=curl_exec($ch);
curl_close($ch);
Doesn't WORK
// create the Gateway object
$gateway = new Gateway();
// set our url
$gateway->init($url);
// get the raw response, ignore errors
$response = $gateway->exec();
Doesn't WORK
$file = "http://www.example.com/my_page.php";
if (function_exists('curl_version'))
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $file);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($curl);
curl_close($curl);
}
else if (file_get_contents(__FILE__) && ini_get('allow_url_fopen'))
{
$content = file_get_contents($file);
}
else
{
echo 'You have neither cUrl installed nor allow_url_fopen activated. Please setup one of those!';
}
This doesn't work.
The page I am trying to use file_get_contents on is not on my website. I am trying to use file_get_contents so i can make a simple API for the site owner by reading a page and checking if a certain word is present on the page.
But yeah if anyone has any suggestions PLEASE post below :)
You can check first weather the site is available or not for example a sample code
Code taken from here:
<?php
$cURL = curl_init('http://www.technofusions.com/');
curl_setopt ( $cURL , CURLOPT_RETURNTRANSFER , true );
// Follow any kind of redirection that are in the URL
curl_setopt ( $cURL , CURLOPT_FOLLOWLOCATION , true );
$result = curl_exec ( $cURL );
// Getting HTTP response code
$answer = curl_getinfo ( $cURL , CURLINFO_HTTP_CODE );
curl_close ( $cURL );
if ( $answer == ' 404 ' ) {
echo ' The site not found (ERROR 404)! ' ;
} else {
echo ' It looks like everything is working fine ... ' ;
}
?>
For a full answer you can got to this tutorial Curl IN PHP
I'm trying to use the SPtrans API (http://www.sptrans.com.br/desenvolvedores/APIOlhoVivo.aspx), which is supposed to provide public transport information for the Sao Paulo (Brazil) area.
I'm trying to get in using PHP and curl.
I'm able to put in the requests and can authenticate myself (with a post request to /Login/Autenticar?token={token}. The post request returns a 'true' (and only a 'true').
(It seems that I need to put the token both as a GET and a POST.)
However, if I then put in an information (GET) request, for example to /Linha/Buscar?termosBusca={termosBusca}, I get a consistent return of "Authorization has been denied for this request." message.
You can see this (not) working at:
http://00qq.com/sptrans/index.php
Any thoughts or ideas on this would be extremely helpful.
Here's the code that picks up the data:
function getResult($accesspoint, $page, $postData, $post = true) {
$ch = curl_init();
$t = http_build_query($postData);
$url = $accesspoint.$page."?".$t;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post == true) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
$output = object_to_array(json_decode($output));
return $output;
}
Update
#chesterbr put me on the right track: I had to create, collect and store cookies upon authentication and then use those upon subsequent requests. Below is a proof of concept.
$site["sptrans"]["accesspoint"] = "http://api.olhovivo.sptrans.com.br/v0";
$site["sptrans"]["page"]["Login"] = "/Login/Autenticar";
$site["sptrans"]["page"]["Parada"] = "/Parada/Buscar";
$site["sptrans"]["page"]["Linha"] = "/Linha/Buscar";
$site["sptrans"]["token"] = ""; //This should contain your token.
error_reporting(E_ALL);
ini_set('display_errors', 1);
function object_to_array($data) {
if (is_array($data) || is_object($data)) {
$result = array();
foreach ($data as $key => $value)
$result[$key] = object_to_array($value);
return $result;
}
return $data;
}
function getResult($accesspoint, $page, $postData, $cookie, $post = true) {
$ch = curl_init();
$t = http_build_query($postData);
$url = $accesspoint.$page."?".$t;
// print $url."<br />";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
// curl_setopt($ch, CURLOPT_COOKIESESSION, true);
if ($post == true) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
$output = curl_exec($ch);
curl_close($ch);
$output = object_to_array(json_decode($output));
return $output;
}
//Create a cookie for the duration of the page.
$ckfile = tempnam ("cache/cookies", "spt.");
print "Authentication<br />";
$postData["token"] = $site["sptrans"]["token"];
$output = getResult($site["sptrans"]["accesspoint"], $site["sptrans"]["page"]["Login"], $postData, $ckfile);
print_r ($output);
unset($postData);
print "<hr />";
print "Linha<br />";
$postData["termosBusca"] = "8000";
$output = getResult($site["sptrans"]["accesspoint"], $site["sptrans"]["page"]["Linha"], $postData, $ckfile, false);
print_r ($output);
unset($postData);
print "<hr />";
print "Parada<br />";
$postData["termosBusca"] = "Afonso";
$output = getResult($site["sptrans"]["accesspoint"], $site["sptrans"]["page"]["Parada"], $postData, $ckfile, false);
print_r ($output);
unset($postData);
print "<hr />";
//Delete the cookie
unlink($ckfile);
You can see this work at http://00qq.com/sptrans/index.php
The API requires you to store the cookies from the authentication call and include them in subsequent ones (otherwise, the server can't know those calls belong to the same session, since HTTP is stateless by default).
You can make that in PHP by configuring the cURL library as described in: https://stackoverflow.com/a/12885587. See also http://www.php.net/manual/en/function.curl-setopt.php for more information on such options (search for "COOKIE" options).
I am trying to retrieve this page using curl in php. This page of course requires you to log in because it displays different apps for each user. I have been following the work done on this page, however am not having much success.
So far, in his example I am able to successfully populate the auth variable with the auth token. In the next step however (Below the comment for logging into Android Market) I run into troubles. The output variable that he says should have a 302 code results in a "The document has moved" page which links me back to the Google log in page.
Here is a pastebin to show exactly what I am trying. http://pastebin.com/9Fs9GWxk
Additionally if anyone knows what steps I need to do after this to actually get the page I need that would be amazing. Thanks
Here is something I came up with today for this question that has been modified to work for you:
<?php
$USERNAME = 'you#gmail';
$PASSWORD = 'yourpasswd';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIEJAR);
curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIEJAR);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_URL,
'https://accounts.google.com/ServiceLogin?hl=en&continue=https://market.android.com/mylibrary');
$data = curl_exec($ch);
$formFields = getFormFields($data);
$formFields['Email'] = $USERNAME;
$formFields['Passwd'] = $PASSWORD;
unset($formFields['PersistentCookie']);
// var_dump($formFields);
$post_string = '';
foreach($formFields as $key => $value) {
$post_string .= $key . '=' . urlencode($value) . '&';
}
$post_string = substr($post_string, 0, -1);
curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($ch);
//var_dump($result);
if (preg_match('/^2\d{2}/', curl_getinfo($ch, CURLINFO_HTTP_CODE)) == false) {
die("Login failed");
var_dump(curl_getinfo($ch), $result);
} else {
curl_setopt($ch, CURLOPT_URL, 'https://market.android.com/mylibrary');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_HTTPGET, true);
$result = curl_exec($ch);
echo $result;
}
function getFormFields($data)
{
if (preg_match('/(<form id=.?gaia_loginform.*?<\/form>)/is', $data, $matches)) {
$inputs = getInputs($matches[1]);
return $inputs;
} else {
die('didnt find login form');
}
}
function getInputs($form)
{
$inputs = array();
$elements = preg_match_all('/(<input[^>]+>)/is', $form, $matches);
if ($elements > 0) {
for($i = 0; $i < $elements; $i++) {
$el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]);
if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) {
$name = $name[1];
$value = '';
if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) {
$value = $value[1];
}
$inputs[$name] = $value;
}
}
}
return $inputs;
}