robb73 Posted December 7, 2007 Share Posted December 7, 2007 I've always used integers when passing values in URLs and then using them with $_GET. To check the id is OK I've been using: if (isset($_GET['id'])) { $new_id = (int) $_GET['id']; } else { $new_id = 0; } if ($new_id > 0) { // do something } else { echo '<p>this page has been accessed in error.</p>'; } However, I'd like to pass strings instead of integers so the URL is a bit more meaningful. How would I go about checking its OK in the receiving script? Quote Link to comment Share on other sites More sharing options...
Vizor Posted December 7, 2007 Share Posted December 7, 2007 Do you mean as in filter for bad chars etc? Try urlencode(). Quote Link to comment Share on other sites More sharing options...
robb73 Posted December 7, 2007 Author Share Posted December 7, 2007 I'm worried about someone substituting their own value into the url. I usually end up using the value in an SQL query, so I want to make sure its clean before I run the mysqli_query(). Quote Link to comment Share on other sites More sharing options...
robb73 Posted December 7, 2007 Author Share Posted December 7, 2007 I'm worried about someone substituting their own value into the url. I usually end up using the value in an SQL query, so I want to make sure its clean before I run the mysqli_query(). Maybe I've got this the wrong way round, should I just use mysqli_real_escape_string on the string value passed to $_GET and then used in a mysqli_query() ? Quote Link to comment Share on other sites More sharing options...
robb73 Posted December 7, 2007 Author Share Posted December 7, 2007 Found the answer in a book, I'm just going to test against a regular expression. Posted the solution in case anyone was interested. if (eregi('^[[:alpha:]]+$', stripslashes(trim($_GET['string'])))) { run mysqli_query() } else { send error } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.