Php 登录后无法使用curl显示主页

Php 登录后无法使用curl显示主页,php,curl,Php,Curl,我试图在登录后使用CURL获取我的主页,但我没有 知道为什么不显示它。我认为我的代码有问题 你能检查一下我的代码,告诉我有什么问题吗 <?php $file_contents=file_get_contents("https://www.bcarocks.com/"); $dom = new DOMDocument(); @$dom->loadHTML($file_contents); $xpath = new DomXpath($dom); $imgs = $xpath->

我试图在登录后使用
CURL
获取我的主页,但我没有
知道为什么不显示它。我认为我的代码有问题
你能检查一下我的代码,告诉我有什么问题吗

<?php 
$file_contents=file_get_contents("https://www.bcarocks.com/");
$dom = new DOMDocument();
@$dom->loadHTML($file_contents);

$xpath = new DomXpath($dom);
$imgs = $xpath->query('//*[@id="cimage"]');
foreach($imgs as $img)
{
    $imagesrc=$img->getAttribute('src') . PHP_EOL;
}
?>

<?php
//initial request with login data
if(isset($_REQUEST['submit']))
{
      $user='test';
      $pass='test';
      $captcha=$_REQUEST['j_captcha'];
      $submit=$_REQUEST['submit'];
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, 'https://www.bcarocks.com/');
      curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, "j_username=$user&j_password=$pass&j_captcha=$captcha&submit=$submit");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_COOKIESESSION, true);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie-name');  //could be empty, but cause problems on some hosts
      curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/ip4.x/file/tmp');  //could be empty, but cause problems on some hosts
      $answer = curl_exec($ch);
      if (curl_error($ch)) {
          echo curl_error($ch);
      }

      //another request preserving the session

      curl_setopt($ch, CURLOPT_URL, 'https://www.irctc.co.in/eticketing/home');
      curl_setopt($ch, CURLOPT_POST, false);
      curl_setopt($ch, CURLOPT_POSTFIELDS, "");
      echo $answer = curl_exec($ch);
      if (curl_error($ch)) {
          echo curl_error($ch);
      }
}
?>
<form method="post">
    <img src="https://www.bcarocks.com/<?php echo $imagesrc;?>" />
    captcha:<input type="text" name="j_captcha" />
    <input id="loginbutton" type="submit" name="submit" value="Login"  />   
</form>

" />
验证码:

页面是通过curl加载的,可能是您的登录详细信息不正确。您应该始终使用urlencode()对于您发送的每个参数。

这是因为您首先在此处获取了验证码,然后您再次提交验证码。您正在访问页面,因此它会再次为您生成新的验证码,但您已填充旧的验证码,因此新的验证码与旧的验证码不匹配
明白了吗?

在您引用的
validateloginDetails()表单中
,那是哪里?这只是为了验证没有为验证码输入空白文本框而进行的验证忘记了这一点,现在请再次查看我的代码我的登录详细信息是正确的,我知道并且我能够通过网站成功登录确定现在我已经编辑了正确的用户名和密码请查看您将能够在网站中使用它登录