Welcome Guest, Not a member yet? Register   Sign In
URI Segment Security / Validation
#1

[eluser]dobomode[/eluser]
Is there an easy / built-in way to validate URI segments?

For example, suppose I am at:

Code:
www.domain.com/view/post/423

I want to validate the third segment - <b>423</b> - and ascertain that it's an integer before passing to a where clause of a SQL statement.

Also, I would want to make sure somebody doesn't manually insert in some hack string - does CI automatically call xss_clean on the URI?

Thanks!
#2

[eluser]pistolPete[/eluser]
[quote author="dobomode" date="1234763679"]I want to validate the third segment - <b>423</b> - and ascertain that it's an integer before passing to a where clause of a SQL statement.
[/quote]

There isn't such thing like URI segment validation, but you can easily do it yourself:
Code:
// controller: view
public function post($value)
{
   if(is_numeric($value))
   {
      // call model to select data
   }
}


[quote author="dobomode" date="1234763679"]
Also, I would want to make sure somebody doesn't manually insert in some hack string[/quote]

If you restrict the permitted_uri_chars like that, all attempts to submit a "hack string" are blocked:
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-';
#3

[eluser]TheFuzzy0ne[/eluser]
If you are checking that the third parameter is indeed a number, and you are only using the third parameter, I don't think it's possible for anyone to "manually insert some hack string".
#4

[eluser]kylehase[/eluser]
I agree with dobomode. It would be useful to be able to use the validation methods (now form_validation) on any input, URI segment, cookie and post.




Theme © iAndrew 2016 - Forum software by © MyBB