OpenID with PHP

Source: Internet
Author: User
Tags openid pear
One of the AVBlog2.0 development notebooks

Soy sauce First

OpenID is no longer a novelty, but it is still an awkward state of applause. Promotion strategy is on the one hand, from the user experience point of view, the login process will be possible to jump to the OpenID website, which is accustomed to the normal registration process users a great test. So simpler apps like Facebook Connect make it easier to get to the market. Perhaps OpenID needs a lot of improvement to get a wide range of applications, but the concept of OpenID will undoubtedly shine in the future.

But these and this time blog does not have much relation, I just come out soy sauce: P

To allow your site to support OpenID, the threshold is not high, the following PHP as an example, describes the development of the OpenID login process in PHP environment.

Preparatory work

OpenID's communication process has been a lot of libraries packaged, in the OpenID wiki can see a lot of PHP class library, this time we choose Janrain OpenID Enabled.

The latest release is version 2.1.2, based on the OPENID2.0 protocol, downloaded to the local after the direct run examples folder detect.php, can be prompted to adjust the development environment, the minimum need for PHP pear support. The specific situation can be flexibly handled according to the instructions, the work of environmental adjustment here a stroke.

Run Demo

Client login, already have a ready to use demo for reference, run examples/consumer/index.php, enter the OpenID we want to verify and submit, WIN32 environment will unfortunately appear unable to create/tmp/_php_consumer_ The error of test. This is to save the temporary files during the login process, modify examples/consumer/common.php line 53rd, and change the relative directory.

    $store _path = "./_php_consumer_test";

Rerun demo, still error

Fatal Error:define Auth_openid_rand_source as NULL to continue with an insecure random number generator.

In the 23rd line of auth\openid\cryptutil.php, this defines the auth_openid_rand_source that will be used to generate a random number from a specific file, where a file of the native can be specified, or it can be directly defined as null

Define (' Auth_openid_rand_source ', null);

At this point, if the operating environment is not a problem, the client login demo can be successfully run.

Database schema Run

The above example uses a file to save the temporary files during the login process, OpenID enabled also provides the storage of the database mode, the database connection part is based on the Pear DB Class implementation. In MySQL, for example, the GetStore function for modifying examples/consumer/index.php is as follows

function GetStore () {require_once "auth/openid/mysqlstore.php"; $db =& db::connect (Array (' phptype '  = ') MySQL ', ' username ' = ' root ', ' password ' + ' root ', ' hostspec ' = ' localhost ', ' database ' = ' blog ');    $store = new Auth_openid_mysqlstore ($db);    $store->createtables ();    return $store;}
  • 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: info-contact@alibabacloud.com 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.