Ali Hesari Ali Hesari - 4 months ago 18
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

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

//redirect if not exist query string

plz help...


Since ext-mongo version 1.5 you can check it

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