Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
session_start()php变量_Php_Authentication_Session_Server_Isset - Fatal编程技术网

session_start()php变量

session_start()php变量,php,authentication,session,server,isset,Php,Authentication,Session,Server,Isset,我正在尝试从PHP服务器端验证用户登录系统。我已经被困在这个问题上好几个星期了,似乎在网上任何地方都找不到我的答案。我希望你们能帮助我 每次调用php脚本时,会话变量似乎都丢失了。以下是我的php服务器的日志: [Sun Nov 8 14:28:16 2020] 127.0.0.1:60706 [200]: /api/read.php [Sun Nov 8 14:28:27 2020] Session Variables set! [Sun Nov 8 14:28:27 2020] adm

我正在尝试从PHP服务器端验证用户登录系统。我已经被困在这个问题上好几个星期了,似乎在网上任何地方都找不到我的答案。我希望你们能帮助我

每次调用php脚本时,会话变量似乎都丢失了。以下是我的php服务器的日志:

[Sun Nov  8 14:28:16 2020] 127.0.0.1:60706 [200]: /api/read.php
[Sun Nov  8 14:28:27 2020] Session Variables set!
[Sun Nov  8 14:28:27 2020] admin
[Sun Nov  8 14:28:27 2020] 127.0.0.1:60713 [200]: /api/read.php
[Sun Nov  8 14:54:34 2020] Session Variables set!
[Sun Nov  8 14:54:34 2020] admin
我通过从typescript文件调用php脚本,多次从同一页面调用该脚本:

readRecruitmentNeeds(): Observable<Policy[]>{
  return this.httpClient.get<Policy[]>(`${this.PHP_API_SERVER}/api/read.php`);
}

感谢您的帮助。谢谢

你的问题是什么还不清楚。你能澄清一下吗?@Phil我编辑了我的帖子,让它更清楚。很抱歉,我似乎已经完成了关于原始post的遗漏问题。PHP会话通过cookies进行维护。您需要将XHR调用配置为包含。@Phil需要这样的工作:readRecruementNeeds():Observable{返回this.httpClient.get(
${this.PHP\u API\u SERVER}/API/read.PHP
,{withCredentials:true});这完全取决于
httpClient
是什么。如果是Axios,它可能会工作,但您也可能会遇到CORS问题。试试看
session_start();

$username="admin";
$pwd="admin";

if(isset($_SESSION['uname'])){
  readData();  //run if logged in
  error_log ("User is logged in",0);
  error_log ($_SESSION['uname'],0);
}
else{
  $_SESSION['uname']=$username;
  error_log ("Session Variables set!",0);
  error_log ($_SESSION['uname'],0);
  
}