Single login system

Asked

Viewed 836 times

2

How to create a single login in PHP? That gives access to multiple sites for the user, without having to login to each site. Like Google, which with a single login, you use Google and Youtube.

  • 2

    That is a very broad question.... there are several ways to do it, using frameworks(zend, cake, Languable, joomla, among many others), or pure php, using more front-end features, such as Storage in js, or more back-end, leaving more server account, as well as registered users, validating data and so on.... The network does not work like this, assemble the scope of your project, if any doubt arises in specific tools or functions in the construction, then yes it becomes more applicable....

  • 1

    I find valid what the colleague quoted above. Anyway, something similar to what you quoted reminded me the Oauth, gives a search.

  • 2

    @Williamnovak Thank you

  • 1

    @Marcelobonifazio I would like to create this system in pure PHP, for study!

  • 1

    Better understanding your question, after editing, I believe that Oauth is not a solution or even a study base in your case, even more because of its complexity. In your case, it would be a simple job to work with Session provided they were saved in the same place. Take a look here Session..

  • 1

    @Williamnovak Thank you

Show 1 more comment

1 answer

1


Any session created by default is created a cookie in the browser called PHPSESSID that is saved the session name (in hash) created by your code in the temporary folder of the server.

You can access this cookie using session_get_cookie_params() before the session_start() that will show some parameters:

Array
(
[lifetime] => 0 
[path] => /
[domain] => 
[secure] => 
[httponly] => 
)

the [lifetime] => 0 indicates that when the browser is closed the cookie will disappear and thus the session will be closed.

In this way, whenever a session is opened, a cookie is created. I don’t see why we don’t use cookies in this case:

  • Create a cookie with a name set so that other sites can access.
  • Make the cookie value a key/token (hash) that you create whenever the user logs into one of the participating sites.
  • This hash is saved in the database that all participating websites have access to.
  • Make a check in db (user / key / cookie ) each time he accesses something on any of the sites to verify the identity of this user or log in automatically. You can use machine ip as well.

So he will only log in to any of the sites.

Of course there is a whole security involved that you will have to realize.

I hope I’ve helped.

Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.