我有几个文件夹(每个客户一个),我在其中保存了只有他自己才能访问的图像。
这些文件夹通过 htpasswd 进行保护,我尝试在用户正常登录后通过 cUrl 登录,并保持此 session 处于事件状态,并允许用户仅导航和访问他的文件夹图像。
在我的身份验证 Controller 中,我正在这样做:
$username = 'username';
$password = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'routeToOneFileInHisFolder');
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
我还尝试为 COOKIEJAR 和 COOKIEFILE 设置curl_setopt,但没有不同的结果。我不知道我是否采用了错误的方法或者是否缺少一些代码。
最佳答案
您可以使用$_SESSION,即...
//put this in the top of your php
session_start();
//then store the user and password in the session...
$_SESSION['username'] = 'username';
$_SESSION['password'] = 'password';
// replace in your code anywhere the $username and $password variables
// with the new $_SESSION['username'] and $_SESSION['password']
关于php - 通过 CURL 登录 htpasswd 并将 session 保留在浏览器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48562669/