簡體   English   中英

使用PHP和CURL登錄到站點

[英]Login to a site using PHP and CURL

對我來說,唯一的問題是它沒有用於表單提交的html按鈕,而是使用沒有名稱屬性的css樣式的自定義按鈕。 這是表格

<form name="login_form" method="post" action="index.php" onsubmit="loginFormSubmit(this)">
        <div style="position:absolute;top:-1500px;"><input type="submit" value="sub"></div>
        Username:<input name="username" size="20" maxlength="32"><br><br>
        Password:<input type="password" name="passwd" size="20" maxlength="32">
    </form>

Button的HTML代碼,如果在標記之外

<div style="position: absolute; width: 54px; height: 20px; top: 382px; margin-left: 312px; cursor: pointer; color: rgb(255, 255, 255); font-style: normal; font-weight: normal;" onmouseover="fFOB(this)" onmouseout="fFNN(this)" onclick="loginFormSubmit(document.login_form)">Login</div>

這是我的PHP代碼

    <?php
$username="yyyyy"; 
$password="xxxxx"; 
$url="http://example.com/login.php"; 
$cookie="cookie.txt"; 
$postdata = "username=".$username."&passwd=".$password; 
$postdata = "username=$username&passwd=$password";

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 

echo $result;  
curl_close($ch);
?>

更改類型,例如

 method = 'get'

在表單標簽和php代碼中使用

GET['username'],GET['password'] 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM