duan198409 2019-02-27 02:36
浏览 212

你如何努力将HTML / JS与PHP完全分开?

I've been working and programming for a lot of time, but this simple yet a bit complicated question is always in my mind... this will be about core and plain PHP.

I want to know how can I archieve having just HTML/js files interacting with the server without changing the extension from .html to .php as effective as possible using just the necessary requests.

for example:

I have this website that has a login page:

  1. the user types his username and passwork and its sent using AJAX to auth.php
  2. auth.php do its thing then creates a $_SESSION if valid
  3. the user gets redirected to dashboard.html

Now, how do I get in every reload the current user in the frontend? I can get it in the backend just calling for example $_SESSION["username"] for the purpose of having "welcome [the current username]".

The only solution I've got is to do in every redirect/refresh a AJAX request to ask for that (the request is sent to the PHP script and it echoes the session username for example) but I think this would get very heavy for the server.

what are your thoughts?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab实现基于主成分变换的图像融合。
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊