Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-11-2009, 05:04 PM
Apfelfrucht Apfelfrucht is offline
 
Join Date: Apr 2006
Location: EU
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default The " ?, ?, ?, ? " works but not " ' " with " charset=UTF-8 ", why ?

Hello,

Do you know how and why the " ?, ?, ?, ?, $, ?, & " work well where the " ' " is not, by adding the code below into the PHP file :
Code:
<?php
    header('Content-type: text/html; charset=UTF-8', true);
The code above works well with an image named " Ast?rix " which contains the " ? ", but why it doesn't work with an image named " O'Clock " which contains the " ' " ?

When i try to upload an image named " O'Clock " through that PHP file, the " O'Clock " image file, once uploaded becames " O\'Clock ", with the " \ ", why and how to fix it ?

Please help me

Regards.
Reply With Quote
  #2  
Old 03-11-2009, 06:26 PM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Because the ' character is a terminating character for SQL. It's a form of attack on a website known as "SQL Injection". If you allow the character by itself it can stop the SQL sequence early, then allowing you to execute a different sql statement.

Consider this filename...

'; DELETE * FROM *;.jpg

While this is an illegal windows file name, linux does not care. If someone uploaded a file name like that, the first ' symbol would stop the SQL, then it would execute the next SQL in line (DELETE * FROM *;). So the way you prevent the injection from happening is called "escaping". You "escape" the ' character with a backslash like you saw... O\'Clock. Doing that will prevent the ' character from terminating the SQL sequence early.

Normally, the backslash is not shown. The PHP doesn't show escape characters when they're being used. However, if your PHP is using the quote symbol instead of the apostraphy, then it wouldn't see the backslash as an escape character.
Reply With Quote
  #3  
Old 03-11-2009, 06:53 PM
Apfelfrucht Apfelfrucht is offline
 
Join Date: Apr 2006
Location: EU
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Tiger,

Firstly it's a PHP Upload Form with No Database, which can upload the file directly to the specified folder

Yeah i've tested on Browser like IE or Firefox, the Backslash is became automaticly to slash " / ".

The solution for the " ?, ?, ?, ?, $, ?, & " is with this code :
Code:
<?php
    header('Content-type: text/html; charset=UTF-8', true);
And, what about or is the solution in order to upload a file named like " O'Clock " with the " ' " ?

Thanks.
Reply With Quote
  #4  
Old 03-11-2009, 10:46 PM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It doesn't matter that you're not fussing with the database. Either way, you're using PHP to clean the input given to MySQL before MySQL gets a hold of it. The ' symbol is turned into \' for security purposes. If you "solve" this problem you open your entire website up for attack.
Reply With Quote
  #5  
Old 03-12-2009, 01:35 AM
Apfelfrucht Apfelfrucht is offline
 
Join Date: Apr 2006
Location: EU
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, so i have not to solve it, and why at Imageshack, when i upload an image file named " O'Clock.jpg " with the " ' ", it works well and becames " oclock.jpg " where with my Upload PHP Form becames " o\'clock ", so what is the problem with my Upload PHP Form and how can i make it like Imageshack do ?

Is there a script or way to transform the " ' " automaticly like Imageshack does ?

Regards.
Reply With Quote
  #6  
Old 03-12-2009, 02:06 AM
TigerC10's Avatar
TigerC10 TigerC10 is offline
 
Join Date: Apr 2006
Location: Austin, TX
Posts: 616
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Imageshack actually doesn't name those files the same thing they're named when you upload them. Imageshack and other image hosting services rename the file to a bunch of numbers and letters. When you put in the request for an image by name, there is a custom CGI script that queries the database for images with the same name - then it outputs the matching image if it finds one.

The request for the image name is sent to a CGI script, and the CGI script spits out an image - this is how they can swap out the picture for a different one if the user has gone over their allotted bandwith (you know those pesky "bandwith exceeded" images). It's also why if you specify the wrong image name it will show a picture that says, "invalid image" or something. Do you really thing they go in and replace those pictures entirely every single time they have to?
Reply With Quote
  #7  
Old 03-12-2009, 07:55 AM
Apfelfrucht Apfelfrucht is offline
 
Join Date: Apr 2006
Location: EU
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks a lot for your answers Tiger, i understand what do you mean
Actually, i'm trying not to use any database in order not to take a lot server ressources..

For the symbol " ' ", " _ ", and " - " are now solved and works by a coder who give me the codes like below :
Code:
function cleaner($x){
   //Replacing those weird characters with nothing.
   //This could be altered to replace them with let's say number 0.
   //Added by replacing _ with - also.
   $cleaned = preg_replace('/[^a-z0-9_.@-]/i', '', $x);
   $chars = array('@','_');
   $chars_replacement = array('at','-');
   $cleaned = str_replace($chars, $chars_replacement, $cleaned);
   return $cleaned;   
   }
So now the :
----------------
> " ' " becames " nothing ",
> " ?, ?, ?, ?, $, ?, & " becames " nothing ",
> " _ ", becames " - ".

But i wonder if is there a solution to have a script or code which transform " ?, ?, ?, ?, $, ?, & " to " e, e, a, u, $, ?, & " > I mean no accents

Someone know how please ?

Regards.
Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:15 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.04872 seconds
  • Memory Usage 2,225KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete