starhu
asked on
How to make Php login to different sites?
Hello,
My customer wants to fill a table with site, login name, password data (many rows).
Our php should start once a day and log in to each site, retrieving some data (counting some words on pages).
How can I log in with php to another site? (knowing the user name and password)
Thank you
My customer wants to fill a table with site, login name, password data (many rows).
Our php should start once a day and log in to each site, retrieving some data (counting some words on pages).
How can I log in with php to another site? (knowing the user name and password)
Thank you
How can I log in with php to another site? (knowing the user name and password)Expect that each site will be different, so your script design will use a polymorphic adapter pattern.
Your PHP script will make a GET request for the login page, and will retrieve the HTML. The script will parse the HTML, isolating the form elements and filling in the name and password. Then the script will make a POST request, returning the filled-in form.
For this to work correctly, your script will have to act as a well-behaved web client, accepting and returning cookies, following redirection headers, etc. It's not a task for the faint of heart, and debugging information is very hard to come by. The first place you might want to begin is learning everything you can about HTTP protocol and the PHP cURL library.
Counting words on a web page is relatively easy.
<?php // RAY_count_words.php
error_reporting(E_ALL);
echo "<pre>";
// DEMONSTRATE HOW TO COUNT ALL THE WORDS USED ON A WEB PAGE
// USEFUL MAN PAGES:
// http://php.net/manual/en/function.file-get-contents.php
// http://php.net/manual/en/function.preg-replace.php
// http://php.net/manual/en/function.explode.php
// http://php.net/manual/en/array.sorting.php
// ACQUIRE THE DATA
$url = 'http://www.apache.org/';
$htm = file_get_contents($url);
// MUNG THE DATA INTO LOWER-CASE
$htm = strtolower($htm);
// REMOVE CSS AND JAVASCRIPT
$htm = preg_replace("/\<style.*style\>/", NULL, $htm);
$htm = preg_replace("/\<script.*script\>/", NULL, $htm);
// REMOVE THE HTML TAGS
$htm = strip_tags($htm);
// REMOVE EVERYTHING ELSE BUT LETTERS AND BLANKS
$htm = preg_replace('/[^a-z ]/', ' ', $htm);
// CONVERT ANY EXCESS WHITESPACE TO SINGLE BLANKS
$htm = trim(preg_replace('/\s\s+/', ' ', $htm));
// ACTIVATE THIS TO SEE THE "CLEAN" STRING
// echo PHP_EOL . htmlentities($htm);
// MAKE AN ARRAY OF WORDS
$arr = explode(' ', $htm);
// TURN THE ARRAY OF WORDS INTO UNIQUE KEYS, AND ZERO THE COUNTS
$unq = array_flip($arr);
foreach ($unq as $key => $nothing)
{
$unq[$key] = 0;
}
// COUNT THE WORDS
foreach ($arr as $wrd)
{
$unq[$wrd]++;
}
// SHOW THE WORK PRODUCTS
echo PHP_EOL . "THERE ARE " . count($unq) . " UNIQUE WORDS AMONG ". count($arr) . " TOTAL WORDS";
echo PHP_EOL . "IN ALPHABETICAL ORDER: ";
ksort($unq);
print_r($unq);
echo PHP_EOL . "IN FREQUENCY ORDER: ";
arsort($unq);
print_r($unq);
Best of luck with the project (it's a big one), ~Ray
ASKER
The different websites are websites of other companies.
Every website is different. The only common think is that one can enter a user name in one text field and the password in the other text field.
We don't own these web sites.
This is about completion and tender checking on corresponding web sites.
Every website is different. The only common think is that one can enter a user name in one text field and the password in the other text field.
We don't own these web sites.
This is about completion and tender checking on corresponding web sites.
Ya, agreed every websites are different, but some have there own api to do so, which we have to integrate.
For our website we have info that what additional data has to be passed for the authentication.
You can use rest ,curl method to pass such parameters.
For example for http://lovetomarry.com beside username/password we have to send additional parameters which you would have to pass through url.
file_get_contents,curl,soa p
http://www.electrictoolbox.com/php-file-get-contents-sending-username-password/
For our website we have info that what additional data has to be passed for the authentication.
You can use rest ,curl method to pass such parameters.
For example for http://lovetomarry.com beside username/password we have to send additional parameters which you would have to pass through url.
file_get_contents,curl,soa
http://www.electrictoolbox.com/php-file-get-contents-sending-username-password/
ASKER
Thank you,
We have been trying, so far no success. For example a Joomla site has many hidden parameters for example hash...
We have been trying, so far no success. For example a Joomla site has many hidden parameters for example hash...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or your own websites beside this one.
for yahoo,gmail use OpenId
OpenID is a decentralized authentication protocol that makes it easy for people to sign up and access web accounts.
Yahoo, Google and facebook are all OpenID providers, so simply implementing it on your site will be enough for your users to be able to login using them (and any other OpenID provider).