473,609 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where am I going wrong with the function below?

1 New Member
Expand|Select|Wrap|Line Numbers
  1. function sanitize_string(string $var)
  2. {
  3.     $var = strip_tags($var);
  4.     $var = htmlentities($var);
  5.     $var = stripslashes($var);
  6.     $var = trim($var);
  7.     return mysqli_real_escape_string($var);
  8. }
Jun 17 '16 #1
1 1543
Dormilich
8,658 Recognized Expert Moderator Expert
Where am I going wrong with the function below?
nowhere.

which sanitising function to use strongly depends on the context change, e.g.
- when using prepared statements, escaping for SQL is unnecessary
- htmlspecialchar s() is only for printing into HTML/XML and nothing else.
- strip_tags() is only against XSS
- a decently recent PHP installation doesn’t add slashes and stripping slashes off a windows directory name is not the best of ideas
- trimming a string is a bad idea if you need to retain whitespace

essentially, you always have to decide which sanitisation you need depending on the circumstances.
Jun 18 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
307
by: Vinodh | last post by:
Hi, I created an ASP.NET application in VB.NET. I put one text box (Textbox1) and a button (button1) to the web form (webform1). Then I clicked on the button and add the following code. Textbox1.text = "Hello World" When I ran the project and put the cursor in the text box
10
1501
by: Richard Bixler | last post by:
Hello - I have a project in VB.NET (framework version 1.1), in which I use the function InStr in the following form: Public Function InStr(ByVal String1 As String, ByVal String2 As String, Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As Integer (which is what Intellisense prompts), rather than the form: Public Function InStr(ByVal Start As Integer, ByVal String1 As String, ByVal String2 As String, Optional ByVal...
0
960
by: Adam Honek | last post by:
I'm having this odd bahaviour with the new .net.mail SMTP sending code below. It either gives me an exception error or no error but the main form doesn't show making it seem as if it's not finishing correctly and blocking the thread from launching the new form. I'm testing it in form_load() but this shouldn't matter.
2
1655
by: John Austin | last post by:
I thought I would experiment for the first time with an Image standard control in VS 2005. I pressed create web site, I copied a jpg into the App_Data folder, added an image control to Default.aspx and set the ImageUrl to the jpg ( ~/App_Data/Picture.jpg ). The picture appears in the designer, but when I run the page there is no picture. What am I doing wrong - I have no idea! -- John Austin
6
1310
by: Adam | last post by:
Hi everyone, I figured by doing a larger project, I could start to learn how objects and classes work in PHP, but I am running into a problem. I am trying to write a sudoku generator. I was going to make a cell class to hold the potential values of a cell... class cell { public $potentialValues = array(1,2,3,4,5,6,7,8,9);
15
2677
by: E-Dot | last post by:
I am trying to write a program which asks the user to enter a number in the interval , the program then gives the natural logarithm of that number, using the series for log(x+1)... Here is what I have so far and can't figure out what i'm doing wrong. any help would be greatly appreciated, thanks guys... #include <stdio.h> #include <math.h>
3
3076
by: Sjef Janssen | last post by:
I try to get a tabbed display work both in IE (6 and 7) and Firefox. The last does give a problem. What's going wrong here? I'm totally puzzled. <!doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w4.org/1999/xhtml" xml:lang="nl" lang="nl"> <head> <title>Tabbed display</title> <meta http-equiv="Content-Type" content="text/html; charset=utf8"> <style>
12
1852
by: kang jia | last post by:
hi currently i am doing this car booking website. i would like to only update our inventory one day before customer's start booking time, thus before that, i am still able to rent to other customers. E.g. if she book two month before, i can still rent this car to others within this 2 month, but one day before i need to deduct this car inventory as the next day i have to give this car to that customer. the following is my car inventory...
2
1243
by: prax99 | last post by:
<!DOCTYPE html> <html> <head> <style> #wrapper { width: 2200px; transform: translate3d(0, 0, 0); transition: transform .5s ease-in-out;
0
8053
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8513
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5504
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4007
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.