Ali Hesari Ali Hesari - 2 months ago 12
PHP Question

how to check validation mongodb id with php

i get mongodb id of query string. how to check validation this id? i want if mongodb id not valid redirect to another url

get query string:

if(count($_GET)>0 && $_GET['uid']){

//get id from string query
$query = array("_id" => new MongoId($_GET

['uid']));
$user = DB::findone('users',$query);

}else{
//redirect if not exist query string
header('location:'.ADMIN_URL.'/items/forbidden.php');
}


plz help...
thanks

Answer

Since ext-mongo version 1.5 you can check it

if(isset($_GET['uid']) && MongoId::isValid ($_GET['uid'])) { 
 // Your code here 
}

php.net mongoid.isvalid

Comments