duanfu3884 2016-05-16 04:04
浏览 36

如何基于会话变量重定向html页面

I am using html, javascript, and php. My login.htm page lets the user enter the login details. It then submits through the javascript to a php page checkinglogin.php which checks the login details against a database. The call from the javascript to php is asynchronous. So it waits for the response from php page.

The checkinglogin.php page checks against the database and then responds to the javascript

  1. If successful it starts the session and sets a session variable with the user id.
  2. Sends back a message to the javascript either Error or "Success"

The javascript inturn (depending on the response from php) displays the error OR redirects the user to a new page listing.htm

All is working fine.

Now I want to be able to display the listing.htm page only if the session has been started and the user has successfully logged in. Currently, listing.htm is accessible if dont log in and just type in the url in the browser.

My idea is that somehow if we can check on listing.htm page that if the session variable is not set then redirect the user to the login.htm page.

Not sure what can be done here to achieve the required functionality.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来