douchanxiu5636 2017-01-25 14:03
浏览 29

理解PHP文件和AJAX调用

I'm slowly learning PHP ;-) I'm having difficulties understanding how separate PHP-files work together.

I make AJAX calls to different php files that all need to be connected to the backend (Parse). Such as:

sign_up.php
login.php
verify_email.php
get_something_out_of_the_database.php

What is the standard way to stay logged in over the different php files? (or what is the google search term for it..?)

Update: Thanks for all your answers about 'sessions'. I doesn't work very well yet, so i made a new question.

Thanks!

Remzo

  • 写回答

3条回答 默认 最新

  • dpchen2004 2017-01-25 14:11
    关注

    You can do this for example by storing the login-data in a session-variable and checking it at the start of every new page.

    Example: You check if login-data is valid. Then

    session_start();
    $_SESSION["login"] = $loginname;
    

    At the start of another page:

    session_start();
    if(!isset($_SESSION["login"]) || $_SESSION["login"] != "check_somehow")
    {
      header("Location: logout.php");
      exit;
    }
    

    For logging out you can use

    session_start();
    session_destroy();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错