[PHP]Secure your game
Posted: Thu Sep 15, 2011 7:54 pm
Hello all,
I want to tell you something about how you can secure your game and why you should..
So the two dangerous things i know are mysqlinject and xss (Cross site scripting)
Let's talk about mysqlinject first..
So what is mysqlinject?
Mysqlinject is code used by someone who want's to do bad stuff XD
they get stuff out of your database just by simple code
this can happen via all ways
e.g index.php?id=1, the user can put whatever he wants after ?id=, because you will read the id, and get it (maybe) out of the database,
also this can happen via simple login or register forms so in a login form if your code is
$mysql_query = ("SELECT * FROM users WHERE username = '".$_POST['username']."' AND password = '".$_POST['password']."'");
if someone enters something like ' OR '' or something (i can't mysqlinject so..) he can log in to any account
How do i protect my site?
use mysql_real_escape_string
How do i use it?
$username = mysql_real_escape_string($_POST['username']);
now i'm going to talk about XSS (Cross site scripting)
What is xss?
XSS is inserting any other code (mostly javascript i think) into a text box or something
and this could really have bad results.. like when a user registers his username as a javascript code that links to another site..
Everytime your username is on a page it will redirect everyone on that page to the other website..
because the javascript code will be included on every page where the username stands..
How do i protect my site?
Well actually it's really easy,
htmlentities($_POST['username']);
so what does it do?
It converts all the html characters to plain text
so when you enter like <b>Hello</b> it will print it out as <b>hello</b> and will not execute the script (hello)
and the more you secure the better
I hope this helped you a little bit =)
I want to tell you something about how you can secure your game and why you should..
So the two dangerous things i know are mysqlinject and xss (Cross site scripting)
Let's talk about mysqlinject first..
So what is mysqlinject?
Mysqlinject is code used by someone who want's to do bad stuff XD
they get stuff out of your database just by simple code
this can happen via all ways
e.g index.php?id=1, the user can put whatever he wants after ?id=, because you will read the id, and get it (maybe) out of the database,
also this can happen via simple login or register forms so in a login form if your code is
$mysql_query = ("SELECT * FROM users WHERE username = '".$_POST['username']."' AND password = '".$_POST['password']."'");
if someone enters something like ' OR '' or something (i can't mysqlinject so..) he can log in to any account
How do i protect my site?
use mysql_real_escape_string
How do i use it?
$username = mysql_real_escape_string($_POST['username']);
now i'm going to talk about XSS (Cross site scripting)
What is xss?
XSS is inserting any other code (mostly javascript i think) into a text box or something
and this could really have bad results.. like when a user registers his username as a javascript code that links to another site..
Everytime your username is on a page it will redirect everyone on that page to the other website..
because the javascript code will be included on every page where the username stands..
How do i protect my site?
Well actually it's really easy,
htmlentities($_POST['username']);
so what does it do?
It converts all the html characters to plain text
so when you enter like <b>Hello</b> it will print it out as <b>hello</b> and will not execute the script (hello)
and the more you secure the better
I hope this helped you a little bit =)