php - 使用 curl 登录 PHP 站点
问题描述
我尝试登录 PV-Meter,它使用 php+cookies 进行登录。如果我用 Firefox 复制帖子,我会得到这个
curl 'http://192.168.96.68/shared/getDeviceData.php' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0' -H 'Accept: */*' -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' --compressed -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'X-Requested-With: XMLHttpRequest' -H 'Origin: http://192.168.96.68' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: http://192.168.96.68/home.php' -H 'Cookie: lang=de; PHPSESSID=tqoehqr3n9iclggolii9rc0mn2; lang=de' --data-raw 'showActiveDeviceStatus=true'
它工作,unitl cookie exprires 所以我想,我必须登录,保存 cookie 并再次调用页面,但我没有成功
如果我尝试:
curl --cookie-jar cookies.txt --data passphrase=pass.word --data username=admin http://192.168.96.68/home.php
之后
curl -b cookies.txt http://192.168.96.68/home.php
-> 没有成功
有什么想法我忘记了吗?
html页面代码
<!DOCTYPE HTML> <html lang="en"><head><title>MaxWeb XPN</title><meta charset="UTF-8" />
<meta name="theme-color" content="#fcbf00">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
<link rel="stylesheet" href="css/unicorn-login.css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="css/xpn.css" />
<!--[if lt IE 9]>
<script type="text/javascript" src="js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="container">
<div id="logo" >
<img class='img-responsive' src='img/logo_xpn.png'/> </div>
<div id="loginbox">
<form id="loginform" action="home.php">
<br>
<div class="input-group input-sm">
<span class="input-group-addon"><i class="fa fa-user"></i></span><input class="form-control" type="text" id="username" placeholder="Benutzername" />
</div>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span><input class="form-control" type="password" id="password" placeholder="Passwort" />
</div>
<div class="form-actions clearfix">
<input type="submit" class="btn btn-block btn-primary btn-default" value="Login"/>
<br>
<div class="pull-right">
<a href="#recoverform" class="flip-link to-recover grey"><div class='fa fa-question'></div> Support</a>
</div>
</div>
</form>
<form id="recoverform" action="#">
<p><b>Anlagenname:</b> SolarPlant
<br> <b>Seriennummer:</b> 00000000
<br><b>Firmware-Version:</b> 0.0.0
<br><b>Hardware-Version:</b> 0.0.0
<br><b>Ident:</b> XXXXXXXXXXXXXXX<br>
<br><b>Hotline:</b><br>
DE +49 3733 507840 <br>
CH +41 315 281 165 <br>
GB +44 20 38080346 <br>
ES +34 93 2203859 <br>
FR +33 820420684 <br>
IT +39 0418520076 <br></p>
<div class="form-actions clearfix">
<div>
<a href="mailto:hotline@solarmax.com?
subject=sxxxxxxxx%20Support%xxxxxxxx%20xxxxxxxxxx&
body=%0A%0A--------------------------------%0AMaxWeb%20XPN%20Service-Info:%0A%20Serial:%xxxxxxxxx%0APlantname:%20xxxxxxx%0AFirmwareversion:%20x.x.x%0AHardwareversion:%20x.x.x%0AIdent:%20somaxxxxxxx%0A--------------------------------%0A"
class="btn btn-block btn-inverse"><div class="fa fa-envelope"></div> E-Mail Support</a>
</div>
<br>
<div>
<a href="#loginform" class="btn btn-block btn-primary flip-link to-login"><div class="fa fa-arrow-left"></div> Login</a>
</div>
</div>
</form>
</div>
<div>
<img class='img-responsive' src='img/solarmax_logo.png'/>
</div>
</div>
<script type="text/javascript" src="js/respond.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.custom.min.js"></script>
<script src="js/unicorn.login.js"></script>
</body>
<div style="display:none;" id="dialog-confirm" title="Service-Modus">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>Im Service-Modus sind umfassende Änderungen am System möglich. <br>Dadurch kann die Funktionsfähigkeit des Systems beeinträchtigt werden. <br>Für eventuelle Probleme sind Sie selbst verantwortlich!
</div>
解决方案
要访问一个 url,然后发送数据(例如用户名/密码)并在您的客户端计算机上保存 cookie:
curl -c c:\Users\<your-name>\Desktop\cookie.txt -F "login=<your username>" -F "pwd=<your-pwd>" http://192.168.96.68/home.php
读取 cookie 并发送到 url
curl -b c:\Users\<your-name>\Desktop\cookie.txt -L http://192.168.96.68/home.php
推荐阅读
- python - 仅包括包含列表中指定名称的行?
- javascript - Mongoose FindOneAndUpdate:更改值而不覆盖当前值
- c# - 使用 x 的自定义 XML 序列化:
- r - 在层次聚类中为特定进化枝着色
- flutter - 日期时间在颤动中减少
- javascript - Azure 函数仅显示错误响应而不是结果
- html - Shopify // 添加一个“立即购买”按钮,使用正确的变量直接将您发送到结帐
- active-directory - 组策略用户转移到另一台 PC
- r - 在 R 中:tab_model(隐藏多项式)
- lua - 为什么 Splash 没有返回与我检查网站时相同的 HTML?