![]() |
![]() OCAU News - Wiki - QuickLinks - Pix - Sponsors |
|
|||||||
| Notices |
|
Sign up for a free OCAU account and this ad will go away! Search our forums with Google: |
![]() |
|
|
Thread Tools |
|
|
#1 | |
|
Member
Join Date: Apr 2006
Location: NSW
Posts: 1,133
|
Hey guys,
Every time I accept a user supplied variable, I whack it inside a mysql_real_escape_string function because of people like this. ![]() So every time there's a bit of POST data in my PHP, it'll look like this: PHP Code:
PHP Code:
Thanks for any advice!
__________________
Quote:
eBay FS: null | BakeOff Finalist 06 | Google it | 30+ successful trades for total >$1500
|
|
|
|
|
| Join OCAU to remove this ad! |
|
|
#2 | ||
|
Member
Join Date: Feb 2003
Location: Ye Olde Melbourne Town
Posts: 3,245
|
Quote:
Quote:
If you want it really tight you probably should look at parameterized statements From the wiki In PHP version 5 and above, there are multiple choices for using parameterized statements. The PDO database layer is one of them: Code:
$db = new PDO('pgsql:dbname=database');
$stmt = $db->prepare("SELECT priv FROM testUsers WHERE username=:username AND password=:password");
$stmt->bindParam(':username', $user);
$stmt->bindParam(':password', $pass);
$stmt->execute();
Code:
$db = new mysqli("localhost", "user", "pass", "database");
$stmt = $db -> prepare("SELECT priv FROM testUsers WHERE username=? AND password=?");
$stmt -> bind_param("ss", $user, $pass);
$stmt -> execute();
Last edited by Ashpool; 21st April 2010 at 1:48 AM. |
||
|
|
|
|
|
#3 |
|
Member
Join Date: Feb 2003
Location: NSW
Posts: 6,419
|
to change server side session variables they need access to your system (or file system). in other words worrying about sessions would the least of your concerns.
__________________
Democracy's greatest trick was convincing man he was informed. |
|
|
|
|
|
#4 | |
|
Member
Join Date: Apr 2006
Location: NSW
Posts: 1,133
|
Are the examples in my code above server side? I thought all that was handled by the browser :s
__________________
Quote:
eBay FS: null | BakeOff Finalist 06 | Google it | 30+ successful trades for total >$1500
|
|
|
|
|
|
|
#5 | |
|
Member
Join Date: Feb 2003
Location: NSW
Posts: 6,419
|
Quote:
something you dont see, i believe a cookie is created on the browser. the cookie does not contain server varables, but it does contain a key so php can match a client to a particular server session.
__________________
Democracy's greatest trick was convincing man he was informed. Last edited by Luke212; 21st April 2010 at 10:39 AM. |
|
|
|
|
|
|
#6 |
|
Member
Join Date: Aug 2001
Location: melb
Posts: 5,116
|
I'm really confused how the hacker can change the session vars ...
They can change their sessionid ... hence losing their session, but not make a changes to it (luke, i'm glad your here, i thought i was losing it ... more than usual) |
|
|
|
|
|
#7 | |
|
Member
Join Date: Apr 2006
Location: NSW
Posts: 1,133
|
Ohh I see! I knew something session related was stored at the client end (either in a cookie or the URL, depending on the browser) but that's just a key to access session variables, which are all stored server side?
That's going to save me five lines of code and an unnescessary SQL query
__________________
Quote:
eBay FS: null | BakeOff Finalist 06 | Google it | 30+ successful trades for total >$1500
|
|
|
|
|
|
|
#8 | ||
|
Member
Join Date: Apr 2006
Location: NSW
Posts: 1,133
|
Quote:
__________________
Quote:
eBay FS: null | BakeOff Finalist 06 | Google it | 30+ successful trades for total >$1500
|
||
|
|
|
|
|
#9 | |
|
Member
Join Date: Aug 2001
Location: melb
Posts: 5,116
|
Quote:
Similarly, on every request, the client sends his token to the server, which allows the server to keep track of data throughout the session. Each session cookie has a $_SESSION saved on the server. Otherwise the web would suck as it would be completely stateless ... think web 0.5 Last edited by mordy; 21st April 2010 at 1:15 PM. |
|
|
|
|
|
|
#10 | |
|
Member
Join Date: Feb 2003
Location: Ye Olde Melbourne Town
Posts: 3,245
|
Quote:
Why? The theory is that the query is compiled only once and the server holds on to the compiled plan for multiple uses. It's my understanding parameterized queries are the way to go and accepted as current best practices. Looking back now yes it makes sense that the session variables are server side only. SQL injection is pretty common, imagine if hackers could modify the variables then we would have a shit load more of these attacks. Last edited by Ashpool; 22nd April 2010 at 1:49 AM. |
|
|
|
|
|
|
#11 | |
|
Member
Join Date: Aug 2001
Location: melb
Posts: 5,116
|
Quote:
|
|
|
|
|
|
|
#12 | |
|
Member
Join Date: Feb 2003
Location: NSW
Posts: 6,419
|
Quote:
__________________
Democracy's greatest trick was convincing man he was informed. |
|
|
|
|
|
|
#13 | |
|
Member
Join Date: Oct 2004
Location: Singapore
Posts: 6,255
|
Quote:
If you are using a DBMS that caches queries and you're not using parameterized queries then it compiles the query every time its executed. Which makes it slower. |
|
|
|
|
![]() |
| Bookmarks |
|
Sign up for a free OCAU account and this ad will go away! |
| Thread Tools | |
|
|