Geek Geek - 3 months ago 11
PHP Question

Get url parameter from friendly url value

i am using a url re write rule to change url to friendly.

my link now shows like this

http://domain.com/user/10002

what i am trying to do is if the user modifies the url uid under 10000 it will redirect to main page.

This worked before re write but not anymore

<?php


if(empty($_GET['user']) || $_GET['user'] <10000 ) {
redirect(ROOT_URI);
exit;
}
?>

RewriteRule ^user/([^/][0-9]*)$ user/profile.php?user=$1

Answer

As $_GET['user'] is a string you should change your code like this:

if(empty($_GET['user']) || intval($_GET['user']) <10000 ) {
    redirect(ROOT_URI);
    exit;
}

?>