API-work for kassa.neuf.no

* Starts /api/register.php as primary endpoint for kassa
* Started work on simple card number updates in cardnumber.php
* Reworded sms/register.php
* Update README with markdown syntax
This commit is contained in:
nikolark committed 2015-07-13 23:55:37 +02:00
1 parent 6170baef22
commit 2615f7154d
10 files changed
+310 -110

No files matched your search

+35 -19
View File
@@ -1,15 +1,26 @@
<?php
set_include_path("../includes/");
set_include_path("../includes/".PATH_SEPARATOR.get_include_path());
require_once("../includes/DB.php");
require_once("../inside/credentials.php");
/* Set HTTP response code */
function set_response_code($code) {
if(!is_int($code)) {
return false;
if( !function_exists('set_response_code') ) {
function set_response_code($code)
{
if (!is_int($code)) {
return false;
}
header('X-Ignore-This: something', true, $code);
}
header('X-Ignore-This: something', true, $code);
}
function return_json_response($data, $response_code=200) {
if($response_code != 200) {
set_response_code($response_code);
}
die(json_encode($data));
}
@@ -40,24 +51,29 @@ function get_db_connection($fetch_mode=NULL, $options=NULL) {
}
function clean_phonenumber($pn) {
$pn = preg_replace('/[^0-9\+]/', '', $pn); // remove everything except valid chars
$pn = preg_replace('/^00/','+', $pn); // replace starting 00 with +
// norwegian phone numbers
if( strlen($pn) === 8 && ($pn[0] === "4" || $pn[0] === "9") ) {
$pn = "+47".$pn;
if( !function_exists('clean_phonenumber') ) {
function clean_phonenumber($pn) {
$pn = preg_replace('/[^0-9\+]/', '', $pn); // remove everything except valid chars
$pn = preg_replace('/^00/', '+', $pn); // replace starting 00 with +
// norwegian phone numbers
if (strlen($pn) === 8 && ($pn[0] === "4" || $pn[0] === "9")) {
$pn = "+47" . $pn;
}
// ...without +
if (strlen($pn) === 10 && $pn[0] === "4" && $pn[1] === "7" && ($pn[2] === "4" || $pn[2] === "9")) {
$pn = "+" . $pn;
}
return $pn;
}
// ...without +
if( strlen($pn) === 10 && $pn[0] === "4" && $pn[1] === "7" && ($pn[2] === "4" || $pn[2] === "9") ) {
$pn = "+".$pn;
}
return $pn;
}
// E.164
function valid_phonenumber($phone) {
return preg_match('/^\+?\d{8,15}$/i', $phone);
if( !function_exists('valid_phonenumber') ) {
// E.164
function valid_phonenumber($phone) {
return preg_match('/^\+?\d{8,15}$/i', $phone);
}
}