简体   繁体   English

登录页面和具有相同URL的主页在facebook中

[英]login page and home page with same url in facebook

How did facebook manage to have login page and home page of a user with same domain name? Facebook如何管理具有相同域名的用户的登录页面和主页? When the user click on login button, he should be redirected to another page.It seems like this is not happening in case of facebook,as there is not apparent chane in the URL 当用户单击登录按钮时,应该将其重定向到另一个页面。对于facebook,这似乎没有发生,因为URL中没有明显的混乱

Facebook (like many other websites) keeps track of whether a user is logged in. It does this by starting a 'session' on the server side, and having the web browser send a cookie when a page is requested. Facebook(与许多其他网站一样)会跟踪用户是否已登录。它通过在服务器端启动“会话”,并在请求页面时让Web浏览器发送cookie来进行此操作。

What happens is: You request www.facebook.com , the server sees that you are not logged in so it shows a page to login. 发生的情况是:您请求www.facebook.com ,服务器看到您尚未登录,因此显示要登录的页面。 When you login it redirects to the same page, but this time the server gets a cookie that shows you are logged in. And based on this it shows you your homepage. 登录时,它会重定向到同一页面,但是这次服务器将获得一个cookie,显示您已登录。基于此,它会显示您的主页。

When I go to login I am on $DOMAIN/login.php and went I hit login I go to $DOMAIN/home.php 当我登录时,我在$ DOMAIN / login.php上,然后单击“登录”,我进入了$ DOMAIN / home.php。

You could if you wanted have the whole site on ONE page by just controlling what page to actually include() via the $_POST vars or even $_GET vars so what you're saying is very possible. 如果希望通过$ _POST变量甚至$ _GET变量控制要实际包含()的页面,则可以将整个站点放在一个页面上,因此您所说的是很有可能的。

ie

if(login_vars_are_set){
   try{
     login();
   }
}

if(login_successful){
   include(homepage);
}

Does that make sense? 那有意义吗?

Let's say you load index.php. 假设您加载index.php。

In it, before anything is displayed on the screen (for a visitor to see) the server asks: 在其中,在屏幕上显示任何内容(供访客查看)之前,服务器会询问:

    if ($visitor_logged_in == 'NO') {

        echo 'Facebook Homepage blah blah blah';

    }

    if ($visitor_logged_in == 'YES') {

        echo 'Thank you for logging into Facebook!';

    }

Now, above all of that, is a $_GET/$_POST request that sees if any form data was submitted. 现在,最重要的是一个$ _GET / $ _ POST请求,该请求查看是否提交了任何表单数据。 If that is your username/password and it is verified to be correct, the index.php page assigns a value to the $visitor_logged_in variable. 如果那是您的用户名/密码,并且经过验证是正确的,则index.php页将为$ visitor_logged_in变量分配一个值。 If the form data was blank or invalid, it would get a value of 'NO' or, if it was a real user, it would get 'YES'. 如果表单数据为空白或无效,则它将获得“ NO”值;如果是真实用户,则将获得“ YES”。

It's a pretty simple thing and lots and lots of webpages behave like this. 这是一件非常简单的事情,很多网页的行为都像这样。 For one thing it's sometimes easier to have a handful of PHP pages than a separate page for every type of action (instead of using multiple pages, just use multiple IF statements). 一方面,对于每种类型的操作来说,拥有少量的PHP页面有时比单独的页面更容易(而不是使用多个页面,而是使用多个IF语句)。 Another thing is just simpler/easier to learn/manage code. 另一件事是更简单/更容易学习/管理代码。 If you know all of a page's "guts" are on a handful of pages, it makes updating them far easier to work with and troubleshoot. 如果您知道页面的所有“内容”都在少数页面上,则可以更轻松地进行更新和故障排除。

I'm a big fan of self referencing pages, particularly when it is involved with log-in/log-out type behavior. 我是自我引用页面的忠实拥护者,尤其是在涉及登录/注销类型行为时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM