PHP implementation of the single sign-on steps detailed

Source: Internet
Author: User
Tags php foreach
This time for everyone to bring PHP implementation of single Sign-on steps, PHP implementation of single Sign-on note what, the following is the actual case, together to see.

1. Prepare two virtual domain names

2. Create the following files in the root directory of the Openpoor

Index. Php

<?phpsession_start ();? ><! DOCTYPE html>


<?phpsession_start (); if (!empty ($_post[' username ')) {require '). /des.php '; $_session[' username '] = $_post[' username ']; $redirect = ' '; Header (' location: '. UrlEncode ($redirect). ' &code= '. Des::encrypt ($_post[' username '), ' Openpoor '); exit;}? ><! DOCTYPE html>


<?php$redirect = Empty ($_get[' redirect ')? ' ': $_get[' redirect '];if (Empty ($_get[' code ')) {header (' loaction:http://'. UrlDecode ($redirect)); Exit;} $apps = Array (' ');? ><! DOCTYPE html>

3. Create the following files in the root directory of MySpace

Slogin File Completion Session settings

<?phpsession_start (); header (' Content-type:text/javascript; Charset=utf-8 '); if (!empty ($_get[' code ')) {require '.. /des.php '; $username = Des::d ecrypt ($_get[' code '), ' Openpoor '); if (!empty ($username)) {  header (' p3p:cp= ' CURa ADMa DEVa Psao psdo our BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP C or "');  $_session[' username '] = $username; }}?>


<?phpsession_start (); if (!empty ($_session[' username ')) {  echo "Welcome". $_session[' username ']. " The space ";} else{  echo "Please login First";}? >

4.des.php file content is as follows

<?php/** * @see Yii Csecuritymanager;   */class des{public static function encrypt ($data, $key) {$module =mcrypt_module_open (' Des ', ', MCRYPT_MODE_CBC, ');   $key =SUBSTR (MD5 ($key), 0,mcrypt_enc_get_key_size ($module));   Srand ();   $iv =mcrypt_create_iv (Mcrypt_enc_get_iv_size ($module), Mcrypt_rand);   Mcrypt_generic_init ($module, $key, $IV);   $encrypted = $iv. Mcrypt_generic ($module, $data);   Mcrypt_generic_deinit ($module);   Mcrypt_module_close ($module); return MD5 ($data). ' _ '. Base64_encode ($encrypted);   public static function Decrypt ($data, $key) {$_data = explode (' _ ', $data, 2);   if (count ($_data) <2) {return false;   } $data = Base64_decode ($_data[1]);   $module =mcrypt_module_open (' des ', ', MCRYPT_MODE_CBC, ');   $key =SUBSTR (MD5 ($key), 0,mcrypt_enc_get_key_size ($module));   $ivSize =mcrypt_enc_get_iv_size ($module);   $iv =substr ($data, 0, $ivSize);   Mcrypt_generic_init ($module, $key, $IV);   $decrypted =mdecrypt_generic ($module, substr ($data, $ivSize, strlen ($data))); Mcrypt_generic_deinit($module);   Mcrypt_module_close ($module);   $decrypted = RTrim ($decrypted, "n");   if ($_DATA[0]!=MD5 ($decrypted)) {return false; } return $decrypted; }}?>

When the Openpoor log in after the session information to other domain names under the file for processing, in the form of script tags to run.

5. Access and are not logged in at this time

Log in after two domain names

To this we have implemented a simple single sign-on.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

Php+rsa generate key bits in 1024-bit steps

PHP Development API Interface Security verification steps detailed

PHP binary Mutual Conversion calculation implementation steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.