Ali Hesari Ali Hesari - 1 year ago 151
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...

Answer Source

Since ext-mongo version 1.5 you can check it

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download