Skip to content

Commit

Permalink
Improve error handling in OpenID example
Browse files Browse the repository at this point in the history
- properly check parameter types
- catch all exceptions (eg. network error)

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 17, 2016
1 parent 00b9be9 commit 2766460
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/openid.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ function Show_page($contents)
}

/* Grab identifier */
if (isset($_POST['identifier'])) {
if (isset($_POST['identifier']) && is_string($_POST['identifier'])) {
$identifier = $_POST['identifier'];
} else if (isset($_SESSION['identifier'])) {
} else if (isset($_SESSION['identifier']) && is_string($_SESSION['identifier'])) {
$identifier = $_SESSION['identifier'];
} else {
$identifier = null;
Expand All @@ -109,7 +109,7 @@ function Show_page($contents)
/* Create OpenID object */
try {
$o = new OpenID_RelyingParty($returnTo, $realm, $identifier);
} catch (OpenID_Exception $e) {
} catch (Exception $e) {
$contents = "<div class='relyingparty_results'>\n";
$contents .= "<pre>" . $e->getMessage() . "</pre>\n";
$contents .= "</div class='relyingparty_results'>";
Expand Down

0 comments on commit 2766460

Please sign in to comment.