PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Combined Provide Scripts

It is possible to combine all provider functionality in one script. In this case login and trust URLs are omitted, and Zend_OpenId_Provider assumes that they point to the same page with the additional "openid.action" GET argument.

Note

The following example is not complete. It doesn't provide GUI code for the user, instead performing an automatic login and trust relationship instead. This is done just to simplify the example; a production server should include some code from previous examples.

Example 654. Everything Together

<?php
$server 
= new Zend_OpenId_Provider();

define("TEST_ID"Zend_OpenId::absoluteURL("example-9-id.php"));
define("TEST_PASSWORD""123");

if (
$_SERVER['REQUEST_METHOD'] == 'GET' &&
    isset(
$_GET['openid_action']) &&
    
$_GET['openid_action'] === 'login') {
    
$server->login(TEST_IDTEST_PASSWORD);
    unset(
$_GET['openid_action']);
    
Zend_OpenId::redirect(Zend_OpenId::selfUrl(), $_GET);
} else if (
$_SERVER['REQUEST_METHOD'] == 'GET' &&
    isset(
$_GET['openid_action']) &&
    
$_GET['openid_action'] === 'trust') {
    unset(
$_GET['openid_action']);
    
$server->respondToConsumer($_GET);
} else {
    
$ret $server->handle();
    if (
is_string($ret)) {
        echo 
$ret;
    } else if (
$ret !== true) {
        
header('HTTP/1.0 403 Forbidden');
        echo 
'Forbidden';
    }
}

If you compare this example with previous examples split in to separate pages, you will see only the one difference besides the dispatch code: unset($_GET['openid_action']). This call to unset() is necessary to route the next request to main handler.

Zend Framework