Adobe Dreamweaver Forums



Last 10 THreads :         Dreamweaver Help! (Last Post : mollyjm - Replies : 0 - Views : 1 )           »          Re: Change Book or Page Icons? (Last Post : garythebadger - Replies : 0 - Views : 1 )           »          Embedded hyperlink doesn't work (Last Post : Racer-EX - Replies : 0 - Views : 1 )           »          RoboHelp hanging (Last Post : shawntrident - Replies : 4 - Views : 5 )           »          advice please (Last Post : NedWebs - Replies : 1 - Views : 2 )           »          Spry Accordion Panel Default State All Closed? (Last Post : David Powers - Replies : 1 - Views : 2 )           »          Is there a time limit for a full-motion recording? (Last Post : CatBandit - Replies : 2 - Views : 3 )           »          CS4 slow in Leopard (Last Post : Jim Babbage .:CMX:. & .:Adobe Community Expert:. - Replies : 1 - Views : 2 )           »          Spry menu hover issue (Last Post : danantal - Replies : 0 - Views : 1 )           »          Writing in different languages (Last Post : neebie - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Dreamweaver: Main > Dreamweaver Application Development
 
Tags:



Reply
  #1 (permalink)  
Old 04-13-2008, 02:51 AM
patricktr
 
Posts: n/a
Diggs:
Default htmlentities vs mysql_real_escape_string

Stupid question but what's the difference between htmlentities &
mysql_real_escape_string; they both seem to be designed against hackers keying
in html instructions into forms so they 'escape' problem strings (primarily the
apostrophe it seems) and I know that you use mysql_real_escape_string before
writing to a db and htmlentities before re-display user in put on a screen but
why is this separateion necessary - why can't it just be one function?

Playing around I can see that if I enter <p echo 'me' /p>, MRES gives me <p
echo \'me\' /p> (with magic quotes slashes striped), and htmlentities give me
Null so there is clearly a dfference but I don't understand why - can anyone
explain in simple words for a simple brain?

Also does this mean that when validating prior to writing to a db I validate
an htmlentities version of the input but then write a MRES version to the db?
In the example above I would be validating a null string and if it was not a
mandatory field I would end up writing a line of code (albeit escaped) to my
db?
Thanks.:confused;



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-13-2008, 02:51 AM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: htmlentities vs mysql_real_escape_string

.oO(patricktr)

>Stupid question but what's the difference between htmlentities &
>mysql_real_escape_string;


RTFM?

>they both seem to be designed against hackers keying
>in html instructions into forms so they 'escape' problem strings


They are _not_ meant as a protection against hacking.

mysql_real_escape_string() escapes characters, that have a special
meaning in SQL and could break a query. As a side effect it also helps
to prevent SQL injection, but this is not its main purpose.

htmlentities() and htmlspecialchars() (the latter is enough if you use
UTF-8) on the other hand escape chars that have a special meaning in
HTML and might break your markup. As a side effect they also help to
prevent XSS attacks, but again - this is not their main purpose.

>(primarily the
>apostrophe it seems) and I know that you use mysql_real_escape_string before
>writing to a db and htmlentities before re-display user in put on a screen but
>why is this separateion necessary - why can't it just be one function?


They're designed for totally different targets and used in totally
different places.

> Playing around I can see that if I enter <p echo 'me' /p>, MRES gives me <p
>echo \'me\' /p> (with magic quotes slashes striped), and htmlentities give me
>Null


Huh? With htmlentities() you should get the same string with at least <
and > replaced by character references.

>so there is clearly a dfference but I don't understand why - can anyone
>explain in simple words for a simple brain?
>
> Also does this mean that when validating prior to writing to a db I validate
>an htmlentities version of the input but then write a MRES version to the db?
>In the example above I would be validating a null string and if it was not a
>mandatory field I would end up writing a line of code (albeit escaped) to my
>db?
> Thanks.:confused;


Me too, because I don't really get this last part ... anyway, time for
bed now.

Micha
Reply With Quote
  #3 (permalink)  
Old 04-13-2008, 02:51 AM
David Powers
 
Posts: n/a
Diggs:
Default Re: htmlentities vs mysql_real_escape_string

patricktr wrote:
> Stupid question but what's the difference between htmlentities &
> mysql_real_escape_string;


htmlentities() converts special characters to their HTML entities (such
as &amp;, etc.

http://docs.php.net/manual/en/function.htmlentities.php

mysql_real_escape_string() escapes quotes and other control characters
in preparation for inserting content into a MySQL database.

http://docs.php.net/manual/en/functi...ape-string.php

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Reply With Quote


  #4 (permalink)  
Old 04-13-2008, 02:51 AM
patricktr
 
Posts: n/a
Diggs:
Default Re: htmlentities vs mysql_real_escape_string

Guys - appreciate it.
RTFM - well yes ... the php manual has, I'm sure, references to everything
I'll ever want to know about php but it is not always expressed in a way that
is readily graspable by those not steeped in the technical tradition. I am
using a few different books but there is always a certain degree of prior
knowledge assumed and that can lead to confusion - but please bear with me ?
the idiotic questions have got to dry up soon ? haven?t they? See my latest
post.
P.

Reply With Quote
  #5 (permalink)  
Old 04-13-2008, 02:51 AM
Michael Fesser
 
Posts: n/a
Diggs:
Default Re: htmlentities vs mysql_real_escape_string

.oO(patricktr)

>Guys - appreciate it.
> RTFM - well yes ... the php manual has, I'm sure, references to everything
>I'll ever want to know about php but it is not always expressed in a way that
>is readily graspable by those not steeped in the technical tradition.


OK.

>I am
>using a few different books but there is always a certain degree of prior
>knowledge assumed and that can lead to confusion - but please bear with me ?
>the idiotic questions have got to dry up soon ? haven?t they? See my latest
>post.


;-)

No problem. The RTFM wasn't meant rude.

Micha
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 06:11 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk