简体   繁体   中英

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? 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 (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.

What happens is: You request www.facebook.com , the server sees that you are not logged in so it shows a page to login. 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.

When I go to login I am on $DOMAIN/login.php and went I hit login I go to $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.

ie

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

if(login_successful){
   include(homepage);
}

Does that make sense?

Let's say you load 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. 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. 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'.

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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