douci4026 2014-07-09 15:59
浏览 97
已采纳

无法通过curl进行身份验证

I've been unable to authenticate using curl to: https://www.eyez-on.com/EZMAIN/login.php Here's my code (based on question Login to remote site with PHP cURL):

<?php


echo date('l jS \of F Y h:i:s A');
echo "<br>";

//username and password of account
$username = trim($values["email@domain.com"]);
$password = trim($values["mypassword"]);



//login form action url
$url="https://www.eyez-on.com/EZMAIN/login.php"; 
$postinfo = "email=".$username."&password=".$password;

$cookie_file_path = "/cookie/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);

//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, "https://www.eyez-on.com/EZMAIN/account.php");
//do stuff with the info with DomDocument() etc

$html = curl_exec($ch);

echo $html;

curl_close($ch);

?>

I'm wondering if the problem is that the login page form has method GET. Here's a segment of the source of the login page:

    <form action="" method="get" id="login">
        <fieldset>
            <legend>Login</legend>
            <ul>
                <li>
                    <label for="email"><span class="required">User Account</span></label>
                    <input id="email" name="email" class="text required email" type="text" />
                    <label for="email" class="error">This must be a valid email address</label>
                </li>

                <li>
                    <label for="password"><span class="required">Password</span></label>
                    <input name="password" type="password" class="text required" id="password" minlength="4" maxlength="20" />
                </li>


            </ul>
        </fieldset>

        <fieldset class="submit">
                                <input type="submit" class="button" value="Login..." />
        </fieldset>

        <div class="clear"></div>
    </form>

My ultimate goal is once logged in, go to one of my account pages, get some data and create a php variable with the data. The /cookie directory is read/write able by everyone and the cookie.txt file gets written - so that's not the problem. I've worked on this for days............any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • dtvp3625 2014-07-09 18:49
    关注

    Quick tip: use your network tab in chrome so you can see what the form is posting to. This form for example doesn't post to itself but it's posting to https://www.eyez-on.com/EZMAIN/processLogIn.php

    You'll have to make 2 curl calls. The first to the processlogin page, posting your credentials. The variables it takes are email and password, then store the information to a cookie jar and include the cookie jar in your next curl call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题