EAe galera! Esse é o meu primeiro post, espero que possam me ajudar :)
Como fazer um programa para logar-se num site automaticamente? O site é em PHP e pede-se apenas nome de usuário e senha. Li algo sobre, mas era em ASP e n entendi mto bem...
Qualquer coisa o site é http://www.lapafest.com.br
Obrigado!
Cookies.
Do original: http://www.zend.com/codex.php?id=242&single=1Código PHP:<?php
// ----------------------------------------------------------------------------------------
// topic: Track login vars and session_id with cookies and allow autologin
// author: Copyright (c) by Urs Gehrig <admin@circle.ch>
// version: 1.0.0
// update: 26-7-2000
// PHP: php-4.0.0-win32
//
// handling: use this function to ask for a login for first time visitors and track their
// login/password information in cookies on the client's side. you will still
// need to inform the user about enabling cookies. further, there is only a
// a check of login/password against the contents of the cookie, once it is set
// for longer than just the session.
//
// Passwords: your_passwords.txt
// your_login,your_password
// my_login,my_password
//
// Browser: It has been tested and it worked with IE5
//
// Enjoy!
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------------------
function LoginForm(){
global $PHP_SELF;
$header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE>login form</TITLE></HEAD><BODY>';
$footer = '</BODY></HTML>';
echo $header;
?>
<form method="post" action="<?php echo basename($PHP_SELF); ?>" name=loginform>
<table frame=void rules=none WIDTH="300">
<tr>
<td align="left">
login:
<td align="left">
<input type="text" name="login" maxlength=50 size=15 style="width: 120px; font-size: 12px">
<tr>
<td align="left">
password:
<td align="left">
<input type="password" name="passwd" maxlength=50 size=15 style="width: 120px; font-size: 12px">
<tr>
<td align="left">
<td align="left">
<tr>
<td align="left">
<td align="left">
<input type=submit value="login" name="sent" style="width: 50px; heigth: 18px; font-size: 12px">
</table>
</form>
<script type="text/javascript">
<!--
if (document.loginform) {
document.loginform.login.focus();
}
// -->
</script>
<?php
echo $footer;
}
function getItem($item,$str){
$pairs = explode("&", $str);
for($i=0;$i<count($pairs);$i++):
$query[$i] = explode("=", $pairs[$i]);
if($query[$i][0] == $item):
return $query[$i][1];
break;
endif;
endfor;
}
function cke_auth(){
global $PHP_SELF, $sent, $ID, $mysession, $login, $passwd;
// you may select a cookielifetime
$cke_days = 1;
$cke_secs = $cke_days * 24 * 3600; // cookie lifetime in seconds (e.g. here: 1 day)
$cke_time = time()+ $cke_secs;
//$cke_time = 0; // my cookielifetime is lasting the session
if(isset($sent)): // from login form
$login_ok = 0;
if (isset($login) and isset($passwd)):
$fp = fopen("your_passwords.txt", "r");
while (feof($fp) == 0):
$line = chop(fgets($fp,1000));
$arr = explode(",", $line);
if (($arr[0] == $login) and ($arr[1] == $passwd)):
session_start();
setcookie("login", $login, $cke_time);
setcookie("passwd", $passwd, $cke_time);
setcookie("ID", session_id(), $cke_time);
return 1; // authentication succeeded
$login_ok = 1;
break;
endif;
endwhile;
endif;
if(!$login_ok):
return 0; // access denied
endif;
else:
$fp = fopen("your_passwords.txt", "r");
while (feof($fp) == 0):
$line = chop(fgets($fp,1000));
$arr = explode(",", $line);
if (($arr[0] == $login) AND ($arr[1] == $passwd)):
return 1; // authentication succeeded
$login_ok = 1;
break;
endif;
endwhile;
if(!$login_ok):
return 0; // access denied
endif;
endif;
}
// ----------------------------------------------------------------------------------------
// main
// ----------------------------------------------------------------------------------------
//init vars;
$uri = basename($PHP_SELF);
$stamp = md5(srand(5));
if(!cke_auth()): // authentication failed
LoginForm(); // display login form
else: // authentication was successful
//header ("Location: wherever.com");
if (isset($sent)):
echo "logged in from <b>login form</b><br><br>";
echo "Your login name: <b>".$login."</b><br>";
echo "Your password: <b>".$passwd."</b><br>";
echo "<br><br><br><a href='$uri?SID=$ID'>load</a>";
else:
echo "logged in from <b>cookie:</b> ".$ID."<br>";
echo "changing <b>stamp:</b> $stamp<br><br>";
echo "Your login name: <b>".$login."</b><br>";
echo "Your password: <b>".$passwd."</b><br>";
echo "<br><br><br><a href='$uri?SID=$ID&stamp=$stamp'>load</a>";
endif;
endif;
?>
[]s, MM
There are currently 1 users browsing this thread. (0 members and 1 guests)