Current location: Hot Scripts Forums » Programming Languages » PHP » Escaping Html, PHP,etc.


Escaping Html, PHP,etc.

Reply
  #1 (permalink)  
Old 06-27-06, 05:50 AM
juggernaut juggernaut is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Escaping Html, PHP,etc.

I'm a beginner (just the first week) and encountered a problem with my message board script .
I'd be very glad if someone could list some functions that could help me.
I want to display any code as it is written without parsing it..
Reply With Quote
  #2 (permalink)  
Old 06-27-06, 05:57 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Have a look at htmlspecialchars().
Reply With Quote
  #3 (permalink)  
Old 06-27-06, 06:04 AM
juggernaut juggernaut is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Does it replace all `unsafe` symbols?
Reply With Quote
  #4 (permalink)  
Old 06-27-06, 07:04 AM
bd_coder bd_coder is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by juggernaut
Does it replace all `unsafe` symbols?
If you only afraid of HTML tags and <script></script> type exploits , then you can use htmlspecialchars() as nico_swd said.

But for avoiding database related threats (SQL injection) you can escape unsafe characters using addslashes() or you can also use mysql_real_escape_string() for MySQL database.
__________________
------------------------------------
bd_coder
Reply With Quote
  #5 (permalink)  
Old 06-29-06, 04:39 AM
juggernaut juggernaut is offline
Newbie Coder
 
Join Date: Jun 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
addslashes() adds backslashes before quotes, right?
Would htmlentities() do the same also?
Reply With Quote
  #6 (permalink)  
Old 06-29-06, 04:52 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:

addslashes

Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).
http://us2.php.net/manual/en/function.addslashes.php

Quote:
htmlentities

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

Like htmlspecialchars(), the optional second quote_style parameter lets you define what will be done with 'single' and "double" quotes. It takes on one of three constants with the default being ENT_COMPAT:
http://us2.php.net/manual/en/function.htmlentities.php
Reply With Quote
  #7 (permalink)  
Old 06-30-06, 02:29 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
you could use the get_html_translation_table function as well:
PHP Code:

$trans get_html_translation_table(HTML_ENTITIES);

$str "Hallo & <Frau> & Krämer";
$encoded strtr($str$trans);
// output = Hallo &amp; &lt;Frau&gt; &amp; Kr&auml;mer 
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
Need website design or HTML coding help? website_help HTML/XHTML/XML 0 05-26-05 12:07 PM
Please help insert html into php idforforums PHP 5 04-06-05 11:29 PM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.