dtr32221 2015-12-16 02:53
浏览 37

从非预期的源登陆php文件

I suspect this question is asked before but I am having trouble wording it in one sentence so apologies if it is a duplicate but I did ask Google quite a lot but getting answers totally irrelevant to what I am trying to find out.

A bit of context I have a bunch of html and php files that deal with authentication. I have a login.html form that calls home.php which (1) authenticates user based on username and password and then (2) displays home screen. So the home.php has the following variable assignments:

$username = $_POST[“username”];

$password = $_POST[“password”];

The problem is when I am using a different file “change_password.php” which is called from a form in “change_password.html.” In the php file, there are only three variables: $oldpword, $newpword and $newconfirmationpword which is all I need to change password. And once the password is successfully changed, I expect the user to press the “home” button (home.php).

However, when the home button is selected and the home.php file is run, I get an error saying that the variable $username and $password is undefined. I suspect it is because the form that called the change_password.php file did not have $username and $password variables in their <input> element. As such, when the two assignment codes are run, the $_POST[] variables are empty (or undefined).

Is there a way around this? My ultimate aim is to get rid of the undefined errors.

  • 写回答

2条回答 默认 最新

  • duanhuan6336 2015-12-16 03:03
    关注

    The $_POST array is available everywhere since it is a super global. You can access these values anywhere you'd like. Just make sure that you have used session_start();

    $username = $_POST[“username”];
    
    $password = $_POST[“password”];
    

    Set the variables BEFORE you use them.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)