halifaxer
03-04-2009, 10:57 PM
Yes, I'm afraid it's true. It's been done to death and I can understand the archive posts about this, but just to clear something up in my own head related to my site:
I have a product website that uses variable in the url to display the related products. I have 2 examples I want to run through. The first would be...
www.mysite.co.uk/product_page.php?cat=10
From here, the sql script that runs with it would be something like...
"SELECT * FROM products WHERE cat='$_GET[cat]'";
Now, is it true that because the variable of "cat" will only ever be a integer as far as my database is concerned, by changing the above to the following I have made this secure against attack...
"SELECT * FROM products WHERE cat=".intval($_GET['cat']);
Second question is how to change it round, so that if someone is performing a SEARCH on my website and the variable is definitely not going to be an interger, how do I protect myself?
www.mysite.co.uk/product_page.php?search_term=chocolate+vanilla
How do I secure the following:
"SELECT * FROM products WHERE name LIKE '%$_GET[search_term]%'";
All help greatly appreciated, as just can't get my head round it to be honest - it's nothing as drastic as usernames and passwords, but still very important to me!
:)
I have a product website that uses variable in the url to display the related products. I have 2 examples I want to run through. The first would be...
www.mysite.co.uk/product_page.php?cat=10
From here, the sql script that runs with it would be something like...
"SELECT * FROM products WHERE cat='$_GET[cat]'";
Now, is it true that because the variable of "cat" will only ever be a integer as far as my database is concerned, by changing the above to the following I have made this secure against attack...
"SELECT * FROM products WHERE cat=".intval($_GET['cat']);
Second question is how to change it round, so that if someone is performing a SEARCH on my website and the variable is definitely not going to be an interger, how do I protect myself?
www.mysite.co.uk/product_page.php?search_term=chocolate+vanilla
How do I secure the following:
"SELECT * FROM products WHERE name LIKE '%$_GET[search_term]%'";
All help greatly appreciated, as just can't get my head round it to be honest - it's nothing as drastic as usernames and passwords, but still very important to me!
:)