我创建了一个登录页面,该页面接受用户的输入,并检入数据库以确保其正确的用户身份。用户登录后,单击任意网页按钮将注销而不是将我重定向到请求的页面。单击任何网页后,它将重定向到主服务器而不是在本地主机上运行。我试图获取会话密钥,但对我不起作用。
问题是我在会议上发布信息的网站。当我发布详细信息时,服务器端不会创建cookie并传递回去。我查看了“网络”标签,看到那里正在设置会话cookie,是否可以从标题中获取该会话cookie?
我试图制作一个自定义cookie,然后复制粘贴session-cookie,但这是行不通的。使用过的其他用户代码,仍然存在相同的问题
<?php
session_start();
$cookie="C:/xampp/htdocs/cookie.txt";
$url="https://online-learning.aau.ac.ae/moodle/login/index.php";
$_COOKIE['username'] ="xxxxx";
$_COOKIE['password']="xxxxx";
$anchor = "";
setcookie("MoodleSession","690qciai223fgflduqjtiu5ei3");
// $useragent = $_SERVER['HTTP_USER_AGENT'];
// $phpsessionid= $_COOKIE[session_name()]=session_id();
// $strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
$postFields = array('username' => $_COOKIE['username'] ,'password' =>$_COOKIE['password'], 'anchor' => $anchor ,
'submit'=> 'submit' );
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('online-learning.aau.ac.ae'));
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_COOKIE, $cookie);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt ($ch, CURLOPT_REFERER, $url);
$response = curl_exec($ch);
if(!$response){
echo "logged out";
}
else {
curl_setopt ($ch, CURLOPT_URL, "https://online-learning.aau.ac.ae/moodle/my/");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: online-learning.aau.ac.ae'));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
// print_r(curl_getinfo($ch));
echo $response;
}
登录时出现未定义的错误,我希望curl通过从服务器端获取会话cookie来制作cookie,并让我保持登录状态,直到注销为止