{"_id":"56d412b38001e30b00896dd5","__v":10,"parentDoc":null,"user":"55116f88e2990b0d00fb0552","version":{"_id":"568fce2b04440a1700e4cb4a","project":"568fce2a04440a1700e4cb47","__v":20,"createdAt":"2016-01-08T14:56:43.101Z","releaseDate":"2016-01-08T14:56:43.101Z","categories":["568fce2b04440a1700e4cb4b","568fd1b8b700ce0d002f4b1c","568fd23804440a1700e4cb5b","568fd2444719c119002ce5d8","568ff21204440a1700e4cbc1","5693732c8aa8040d009f2c28","5693738393445b0d00abdad0","5693740093445b0d00abdad1","56937445974aaa0d001ca699","5693b82173f48f0d0075c90d","5694c4cd1005590d0062cb25","569f854466a5640d00efa54c","56a264cdd15dd70d008d825b","56aa56bf318e6c1700a19ddb","56b0e6347ae4550d000627bd","56b200c0f48f270d00e0de6f","56b200c6f48f270d00e0de70","56b22a9665ddf50d0076ba40","56e92ef71996862200fd7f42","574d6577fb835c0e00ca316a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"568fce2a04440a1700e4cb47","category":{"_id":"56b22a9665ddf50d0076ba40","version":"568fce2b04440a1700e4cb4a","pages":[],"project":"568fce2a04440a1700e4cb47","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-03T16:28:06.358Z","from_sync":false,"order":4,"slug":"php-quickstarts","title":"PHP Quickstarts"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-29T09:43:15.847Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Full source for these quickstarts can be downloaded from http://download.dynmark.com/Files/API/Quickstart/CS.zip\"\n}\n[/block]\n##Prerequisites\nYou'll need a Dynmark account to be able to send messages. You can use a trial account to send a limited number of free messages for testing.\n\nBefore you start, you *must* have an up to date CA root bundle for cURL. Download the [CA root bundle for cURL](https://curl.haxx.se/ca/cacert.pem), copy it into your PHP directory and update the *curl.cainfo* PHP setting to the path to the new file.\n\n##Registration\nWe're going to create a simple application that registers users and verifies the phone number entered during registration using 2 factor authentication over SMS.\n\n###Build the registration page\nThis page will allow the user to enter their phone number and kick off the verification process\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<html>\\n<head></head>\\n<body>\\n\\n<?php\\nrequire_once(\\\"JsonHelper.php\\\");\\n\\nini_set('display_errors', 'On');\\nsession_start();\\n\\n$phoneNumber = isset($_POST['phoneNumber']) ? $_POST[\\\"phoneNumber\\\"] : NULL;\\nif ($phoneNumber)\\n{\\n    $request = new stdClass();\\n    $request->to = $phoneNumber;\\n    $request->from = \\\"Example\\\";\\n    $result = CallJsonService(\\\"POST\\\", \\\"verify\\\", \\\":::at:::Username@\\\", \\\"@Password@\\\", $request);\\n\\n    if ($result != NULL)\\n    {\\n        $_SESSION['requestId'] = $result->requestId;\\n        header('Location: verify.php', true, 302);\\n\\n        exit();\\n    }\\n    else\\n    {\\n        echo \\\"<div>Sorry, we couldn't sent you a code.</div>\\\";\\n        \\n        foreach ($result[0]->validationFailures as $failure)\\n        {\\n            if ($failure->failureCode == \\\"ToInvalid\\\")\\n            {\\n                echo \\\"<div>Your phone number doesn't look like a valid number.</div>\\\";\\n                break;\\n            }\\n        }\\n    }\\n}\\n?>\\n<form action=\\\"Register.php\\\" method=\\\"POST\\\">\\n    <p>To complete your registration, please enter your mobile phone number. A verification code will be sent to this number.</p>\\n    <input type=\\\"text\\\" name=\\\"phoneNumber\\\" value=\\\"447700090000\\\" />\\n    <input type=\\\"submit\\\" value=\\\"Register\\\" />\\n</form>\\n\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nLets look at the details:\n1. You'll need your Dynmark username and password to authenticate calls.\n2. On initial load we display a form allowing the user to enter their phone number. This form posts to itself for processing.\n3. On receiving the post, the page calls the Verify API's [Create and Send Code](doc:rest-verify-create) to send a code to the user\n4. If the code is sent successfully, we redirect to a verify page which allows the user to enter the code received on their phone.\n\n###Build the verify code page\nThis page allows the user to complete the verification process by entering the code they received on their phone\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<html>\\n<head></head>\\n<body>\\n<?php\\n\\nrequire_once(\\\"JsonHelper.php\\\");\\n\\nini_set('display_errors', 'On');\\nsession_start();\\n\\n$code = isset($_POST['code']) ? $_POST[\\\"code\\\"] : NULL;\\n$requestId = isset($_SESSION['requestId']) ? $_SESSION['requestId'] : NULL;\\n\\nif ($code && $requestId)\\n{\\n    $request = new stdClass();\\n    $request->code = $_POST[\\\"code\\\"];\\n    $result = CallJsonService(\\\"PUT\\\", \\\"verify/\\\" . $requestId . \\\"/validate\\\", \\\"@Username@\\\", \\\"@Password@\\\", $request);\\n\\n    if ($result != null && property_exists($result, \\\"status\\\") && $result->status == \\\"CodeVerified\\\")\\n    {\\n        echo \\\"<div>Your code was correct and is verified.</div>\\\";\\n    }\\n    else\\n    {\\n        echo \\\"<div>Sorry, that code was not recognised. Reason \\\" . ($result == null || !property_exists($result, \\\"status\\\") ? \\\"CodeUnrecognised\\\" : $result->status) . \\\"</div>\\\";\\n    }\\n}\\n?>\\n<form action=\\\"Verify.php\\\" method=\\\"POST\\\">\\n    <p>Please enter the code we sent to complete your registration</p>\\n    <input type=\\\"text\\\" name=\\\"code\\\" />\\n    <input type=\\\"submit\\\" value=\\\"Verify\\\"/>\\n</form>\\n\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nLets look at the details:\n1. On initial load we display a form allowing the user to enter the code they received on their phone. This form also posts to itself for processing.\n2. On receiving the post, the page calls the Verify API's [Validate](doc:rest-verify-validate) to check whether the code is correct\n3. Finally we display a message informing the user whether the code was correct and if not, the reason why it was not successful.","excerpt":"An example of how Verify can be used as part of an authentication process to check the owner of a mobile number","slug":"qs-php-verify","type":"basic","title":"Use Verify to check mobile number ownership"}

Use Verify to check mobile number ownership

An example of how Verify can be used as part of an authentication process to check the owner of a mobile number

[block:callout] { "type": "info", "body": "Full source for these quickstarts can be downloaded from http://download.dynmark.com/Files/API/Quickstart/CS.zip" } [/block] ##Prerequisites You'll need a Dynmark account to be able to send messages. You can use a trial account to send a limited number of free messages for testing. Before you start, you *must* have an up to date CA root bundle for cURL. Download the [CA root bundle for cURL](https://curl.haxx.se/ca/cacert.pem), copy it into your PHP directory and update the *curl.cainfo* PHP setting to the path to the new file. ##Registration We're going to create a simple application that registers users and verifies the phone number entered during registration using 2 factor authentication over SMS. ###Build the registration page This page will allow the user to enter their phone number and kick off the verification process [block:code] { "codes": [ { "code": "<html>\n<head></head>\n<body>\n\n<?php\nrequire_once(\"JsonHelper.php\");\n\nini_set('display_errors', 'On');\nsession_start();\n\n$phoneNumber = isset($_POST['phoneNumber']) ? $_POST[\"phoneNumber\"] : NULL;\nif ($phoneNumber)\n{\n $request = new stdClass();\n $request->to = $phoneNumber;\n $request->from = \"Example\";\n $result = CallJsonService(\"POST\", \"verify\", \"@Username@\", \"@Password@\", $request);\n\n if ($result != NULL)\n {\n $_SESSION['requestId'] = $result->requestId;\n header('Location: verify.php', true, 302);\n\n exit();\n }\n else\n {\n echo \"<div>Sorry, we couldn't sent you a code.</div>\";\n \n foreach ($result[0]->validationFailures as $failure)\n {\n if ($failure->failureCode == \"ToInvalid\")\n {\n echo \"<div>Your phone number doesn't look like a valid number.</div>\";\n break;\n }\n }\n }\n}\n?>\n<form action=\"Register.php\" method=\"POST\">\n <p>To complete your registration, please enter your mobile phone number. A verification code will be sent to this number.</p>\n <input type=\"text\" name=\"phoneNumber\" value=\"447700090000\" />\n <input type=\"submit\" value=\"Register\" />\n</form>\n", "language": "php" } ] } [/block] Lets look at the details: 1. You'll need your Dynmark username and password to authenticate calls. 2. On initial load we display a form allowing the user to enter their phone number. This form posts to itself for processing. 3. On receiving the post, the page calls the Verify API's [Create and Send Code](doc:rest-verify-create) to send a code to the user 4. If the code is sent successfully, we redirect to a verify page which allows the user to enter the code received on their phone. ###Build the verify code page This page allows the user to complete the verification process by entering the code they received on their phone [block:code] { "codes": [ { "code": "<html>\n<head></head>\n<body>\n<?php\n\nrequire_once(\"JsonHelper.php\");\n\nini_set('display_errors', 'On');\nsession_start();\n\n$code = isset($_POST['code']) ? $_POST[\"code\"] : NULL;\n$requestId = isset($_SESSION['requestId']) ? $_SESSION['requestId'] : NULL;\n\nif ($code && $requestId)\n{\n $request = new stdClass();\n $request->code = $_POST[\"code\"];\n $result = CallJsonService(\"PUT\", \"verify/\" . $requestId . \"/validate\", \"@Username@\", \"@Password@\", $request);\n\n if ($result != null && property_exists($result, \"status\") && $result->status == \"CodeVerified\")\n {\n echo \"<div>Your code was correct and is verified.</div>\";\n }\n else\n {\n echo \"<div>Sorry, that code was not recognised. Reason \" . ($result == null || !property_exists($result, \"status\") ? \"CodeUnrecognised\" : $result->status) . \"</div>\";\n }\n}\n?>\n<form action=\"Verify.php\" method=\"POST\">\n <p>Please enter the code we sent to complete your registration</p>\n <input type=\"text\" name=\"code\" />\n <input type=\"submit\" value=\"Verify\"/>\n</form>\n", "language": "php" } ] } [/block] Lets look at the details: 1. On initial load we display a form allowing the user to enter the code they received on their phone. This form also posts to itself for processing. 2. On receiving the post, the page calls the Verify API's [Validate](doc:rest-verify-validate) to check whether the code is correct 3. Finally we display a message informing the user whether the code was correct and if not, the reason why it was not successful.