Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在joomla网站上使用Curl登录_Joomla - Fatal编程技术网

在joomla网站上使用Curl登录

在joomla网站上使用Curl登录,joomla,Joomla,我无法登录joomla站点。我没有任何访问此网站的权限 下面是我使用过的类似代码。这是一个https站点。它给我的是物体被移到了这里 <?php $uname = $_POST['username']; $upswd = $_POST['password']; $url = "https://www.mytestjoomla.com/index.php?option=com_user&view=login"; $ch = curl_init(); curl_setopt($ch,

我无法登录joomla站点。我没有任何访问此网站的权限 下面是我使用过的类似代码。这是一个https站点。它给我的是物体被移到了这里

<?php
$uname = $_POST['username'];
$upswd = $_POST['password'];
$url = "https://www.mytestjoomla.com/index.php?option=com_user&view=login";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE );
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath('./cookie.txt'));
curl_setopt($ch, CURLOPT_HEADER, TRUE );
$ret = curl_exec($ch);
if (!preg_match('/name="([a-zA-z0-9]{32})"/', $ret, $spoof)) {
    preg_match("/name='([a-zA-z0-9]{32})'/", $ret, $spoof);
}

// POST fields
$postfields = array();
$postfields['username'] = urlencode($uname);
$postfields['passwd'] = urlencode($upswd);
$postfields['option'] = 'com_user';
$postfields['task'] = 'login';
$postfields[$spoof[1]] = '1';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
echo $ret = curl_exec($ch);

// Get logged in cookie and pass it to the browser
preg_match('/^Set-Cookie: (.*?);/m', $ret, $m);
$cookie=explode('=',$m[1]);
setcookie($cookie[0], $cookie[1]);
?>

首先你的$postfields['passwd']是错误的,它应该是$postfields['password'],你会得到什么错误?@PratikPrajapati如果服务器不允许你通过CURL访问数据,那么你为什么要这样做?