473,378 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Secureing the data

150 100+
Are this code is secure or what?
what mysql_real_escape_string do in this code i did't see any change in the code in the database?
If not how can i insert it into the database with out harm my database?
and what are the code if he inserted into the database can harm it to test it?

[PHP]
<?php
mysql_select_db("Test",mysql_connect("localhost"," root",""));
$data=mysql_real_escape_string("<?php echo Hello ?>");
if(mysql_query("INSERT INTO test VALUES ('$data','$data')"))
{
echo "True";
}else{
echo "False";
}
$result=mysql_query("SELECT * FROM TEST");
$array=mysql_fetch_assoc($result);
echo $array['name']."<br />";
?>
[/PHP]
Aug 14 '07 #1
6 1223
nathj
938 Expert 512MB
Hi,

Take a look at the following article:

XSRF: What is it, How does it work, and how can you thwart it

Also you can do simple things like remoive invalid characters from any data you load to the database. By sending wvery data item through a function similar to this:
[php]
function secure($data, $plIsEmail)
{
// prevent the majority of attaccks by removing certain elements from the data. Not to be used if the target field is to store HTML in it.
if ($plIsEmail)
{
$replace = array('<' => '' , '>' => '' , '&' => '' , ',' => '' , '*' => '' , '/' => '' );
}
else
{
$replace = array('<' => '' , '>' => '' , '&' => '' , '.' => '' , ',' => '' , '*' => '' , '/' => '' , '@' => '');
}

$data = strtr($data , $replace);
return $data;
}
[/php]

I must admit that I got the basis for this function from someone here on TSDN so I do not take credit for it. Unfortunatley I can't remember who or where, but thaks to whoever it was that wrote this, it works well.

This is one step in the process, reading the article will help even more.

Cheers
nathj
Aug 14 '07 #2
smartic
150 100+
Thank you for this article but it did't answer my question i want to know when i insert data into the database like :
[PHP
]<?php
//data
?>
[/PHP]

are that code can harm the database ?
Aug 14 '07 #3
nathj
938 Expert 512MB
Thank you for this article but it did't answer my question i want to know when i insert data into the database like :
[PHP
]<?php
//data
?>
[/PHP]

are that code can harm the database ?
I am assuming (and perhaps thats my problem) that you are talking about taking data from a form on a web site into your database? In which case someone can load code into the form that could cause problems to your database. Hence I recommended reading the article and removing the potential for harm from any information passed into the database.

I think that I am mis-understanding what you are asking. Do you have any code you could show me so that I can get a better understaning of the question being asked?

Cheers
nathj
Aug 14 '07 #4
smartic
150 100+
my question is : i want to enter php tags into my database like when i write php tags into this forum, how can i secure that ?
Aug 14 '07 #5
nathj
938 Expert 512MB
my question is : i want to enter php tags into my database like when i write php tags into this forum, how can i secure that ?
I understand now.

What I would do is replace the tags with something else, then when you read from the the table you can add the php tags in and now how to format the output. It then just becomes a case of documenting the parsing rules. So when someone writes to the database the tags a rereplaced with the safe equivalent, then when they read from the database they safe equivalent is replaced with the tags.

I am working on a project where I intend to allow html tags in the database. I am going to secure this by only allowing certain people (namely me) access to that functionality. In this case I will just load them as they are.

If you know who is going to be loading the information to the DB then I think you can just add the tags as they are and no harm is done. The potential for trouble comes when you read from the database so that's where you need to be most on your guard.

Cheers
nathj
Aug 14 '07 #6
kovik
1,044 Expert 1GB
my question is : i want to enter php tags into my database like when i write php tags into this forum, how can i secure that ?
You don't need to. The database can't run PHP code, and PHP is only parsed server-side. If you were to try to echo that out, it'd just be displayed as is. No parsing would be done.

As for security, look at the article nathj recommended. Also, make sure you always use mysql_real_escape_string() going into the database, and anytime that you don't want HTML and such, use htmlspecialchars() when getting data out of the database.

And for your earlier question mysql_real_escape_string() stops SQL injection. The data you were putting into it was not an example of SQL injection, and was perfectly fine as is.
Aug 14 '07 #7

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

Similar topics

2
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3...
11
by: Qiangning Hong | last post by:
A class Collector, it spawns several threads to read from serial port. Collector.get_data() will get all the data they have read since last call. Who can tell me whether my implementation correct?...
0
by: Eric | last post by:
I've got a weird problem, regardless of how often I enter: perl -MCPAN -e 'install "Data::Dumper"' I never get a message telling me that it is up-to-date. It will always try to reinstall even...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
3
by: bbernieb | last post by:
Hi, All, Is it possible to access a variable inside of a data binding, without the variable being out of scope? (Note: On the DataBinder line, I get an error message that says "Name 'i' is...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
5
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
0
by: Winder | last post by:
Computer Data Recovery Help 24/7 Data recovering tools and services is our focus. We will recover your data in a cost effective and efficient manner. We recover all operating systems and media....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.