vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   when to use htmlspecialchars_uni (https://vborg.vbsupport.ru/showthread.php?t=234376)

derfelix 01-28-2010 09:33 AM

when to use htmlspecialchars_uni
 
Sorry if this question sounds stupid...

I am adapting an old hack of mine, for a multilanguage site.. (in utf8)
I have title, description and username to put into database (and pull from database and display)

In the very old version info was escaped with addslashes($title),addslashes($description),addsla shes($username)
and before display: stripspashes($title) etc.. etc...

I now would like to do it with :
$db->escape_string($title), $db->escape_string($description), $db->escape_string($username)

Thats ok.. and I dont need the stripslashes anymore..

BUT...
Should I add htmlspecialchars_uni before saving to db? OR after pulling from db?

I meen should i do when saving...
$db->escape_string(htmlspecialschars_uni($title)), $db->escape_string(htmlspecialschars_uni($description)), $db->escape_string(htmlspecialschars_uni($username))

Or should i only add the htmlspecialschars_uni() only before display..
(not before saving but:
$title = htmlspecialschars_uni($title);
$description = htmlspecialschars_uni($description);
$username = htmlspecialschars_uni($username);

I hope you understand what i meen..

F.

Paul M 01-28-2010 10:11 AM

Slashes are for when the data is stored in mysql, to stop sql injection.

htmlspecialchars_uni is for displaying the data, to stop xss attacks.

You should always use escape_string() to add user inputted text to the database, and generally use {vb:var } to display it, as I believe that runs it through htmlspecialschars automatically.

derfelix 01-28-2010 03:11 PM

Thank you for explaining..
So if I understand correctly, I still need the addslashes even if I use escape_string()
because in vbulletin i havent seen one single add or stripslashes anymore....
and what confuses me is that sometimes they save textdata:
escape_string(htmlspecialchars_uni($data))
and sometimes
escape_string($data)

Paul M 01-28-2010 06:10 PM

You dont need addslashes(), escape_string() is its replacement.

As for htmlsp..... its personal choice really, but I would generally store it raw, and clean it on output, especially in vb4 as you can just use vb:var instead of vb:raw.

derfelix 01-28-2010 06:31 PM

Now i understand...
Thank You!
Felix


All times are GMT. The time now is 06:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03590 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete