douju7765 2014-07-10 13:42
浏览 38

有没有一种方法可以在不重定向的情况下重写php中的URL

I've been building a web application and I ran into a rather annoying problem.

My current layout is this:

I have a single file that performs all of the function calls that will inevitably generate the page. Before this file actually generates a viewable page, it first checks if the user is logged in. If the user is logged in, we display the page. If the user is not logged in, we redirect to a login page. Similarly, if the user is logged in and tries to view the login page, the user will be redirected to their home page.

My problem is rather philosophical, but I feel that the redirect is unnecessary as I can easily print the page that the user should be redirected to without performing the redirection. The problem with this method is this does not edit the url.

Here is an example:

  • A user navigates to the page /app/home, which is restricted to logged in users. We hit the database to see if the user is logged in. They are not, so we redirect them to /app/login, which is restricted to users who are not logged in. We hit the database to see if the user is not logged in. They are not, so we display the /app/login page.

The redirection step seems unnecessary, since it adds another unnecessary database hit. I would like it go this way:

  • A user navigates to the page /app/home, which is restricted to logged in users. We hit the database to see if the user is logged in. They are not, so we change the displayed url to /app/login and display the /app/login page.

I want to point out that I don't have a performance issue with this. The second method just seems more elegant. I am aware that there is a javascript method that allows you to modify the url, but I would prefer to do something like this is php, as I haven't left the server yet.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表