| | |
How to secure my web
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
I`ve finished my website,its a social netwrk web in PHP.
Now before i lunch it,i would like to know what are the precautions i should take to protect it from hackers.
please if any one has idea on what i should do,to protect mysql,and my site as a whole.i will be greatefull if u`ll leave me ur suggestions.
Now before i lunch it,i would like to know what are the precautions i should take to protect it from hackers.
please if any one has idea on what i should do,to protect mysql,and my site as a whole.i will be greatefull if u`ll leave me ur suggestions.
Well for one, I would use
mysql_real_escape() on any variable you are passing to MySQL. That should prevent any kind of MySQL injection. I would make sure that your passwords are hashed correctly (using md5() or sha1() ). For added security I would salt your encryptions. See this page for more on salts. Beyond that: Don't store password in cookies (using a unique id or some kind of session id), don't allow code tags (such as <script>) in any kind of use input that will be placed on a page, and be sure that users are authenticated on every page. If you would like, you could give us the address of your site and we can look at some possible security flaws. •
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
thankx guys for replying))
i added the following in my login form.
when i try to login in my localhost it works fine.but in server online it doesn`t work.
When i used addslashes instead of mysql_real_escape_string,the function worked in all sectors.
So what is the difference between these two functions,And if iwant to use mysql_real_escape_string how should i make it to work.??
i added the following in my login form.
php Syntax (Toggle Plain Text)
$user=mysql_real_escape_string($_POST['user']); $password=mysql_real_escape_string(md5($_POST['password']));
When i used addslashes instead of mysql_real_escape_string,the function worked in all sectors.
So what is the difference between these two functions,And if iwant to use mysql_real_escape_string how should i make it to work.??
Well this is definitely an improvement! I believe you problem lies in the fact that the passwords in the database aren't hashed using md5(). You need to create a temporary PHP file on your site with just one line of code:
Then all you have to do is go through you your databases passwords and plug them into the md5 function. After that just replace the old password with the new hashed string. (It is important to make sure that the row that holds passwords can handle a hash. If it is a Varchar it needs to be at least 32 in length). Next, you might need to know if your host has magic_quotes_gpc on (Chances are your host has it on). If so, on the server you will need to change the code so that before you
The reason for this is that when magic_quotes_gpc is on, most strings will automatically be escaped already (but not escaped for MySQL!). You will need to use [code]stripslashes()[/icode] before you use any MySQL escaping functions on it, so that the string is unescaped. This may sound confusing (In fact, it's been deprecated in PHP 5.3 and will be removed in PHP 6), but I believe this could be your solution.
PHP Syntax (Toggle Plain Text)
echo md5("password here");
mysql_real_escape_string() a string that you pass it through stripslashes: PHP Syntax (Toggle Plain Text)
$user = mysql_real_escape_string(stripslashes($_POST['user'])); $password = mysql_real_escape_string(stripslashes($_POST['password']));
Last edited by FlashCreations; Aug 18th, 2009 at 3:47 pm.
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
@FlashCreations,in da web when registering i hash the passwords with md5().thats why when login i was using
the problem started after i added
and how will i know if the magic_quotes_gpc is ON??
also i tested sending comments using
mysql_real_escape_string it worked.
it seems the problem is in the Authorization.
help me in this plz
php Syntax (Toggle Plain Text)
$user=$_POST['user']; $password=md5($_POST['password']);
php Syntax (Toggle Plain Text)
mysql_real_escape_string
also i tested sending comments using
mysql_real_escape_string it worked.
it seems the problem is in the Authorization.
help me in this plz
You will know if magic_quotes_gpc is on by asking your host (If they have the latest version of PHP it shouldn't be!). That might not be it. The only way for us to help you is if you post your code.
•
•
Join Date: Mar 2008
Posts: 217
Reputation:
Solved Threads: 4
here is my login code
]
php Syntax (Toggle Plain Text)
<?php session_start(); $user=mysql_real_escape_string($_POST['user']); $password=mysql_real_escape_string(md5($_POST['password'])); //connecting to databases include"config.php"; $query = "SELECT *FROM login where (user='$user' and password='$password')" ; $result=mysql_query($query); if(mysql_num_rows($result)==1) { $row=mysql_fetch_array($result); $id=$row['id']; $user=$row['user']; $password=$row['password']; $email=$row['email']; $_SESSION['id']=$row['id']; $_SESSION['user']=$row['user']; $_SESSION['password']=$row['password']; $_SESSION['email']=$row['email']; $_SESSION['name']=$row['name']; $_SESSION['photo']=$row['photo']; include "index.php"; }else{ include"wronglogin.php"; } ?>
![]() |
Similar Threads
- Need a secure web conferencing appliance. (Site Layout and Usability)
- Cannot access any secure websites or log into MSN (Viruses, Spyware and other Nasties)
- Creating Web Proxy Servers in Visual Basic (IT Professionals' Lounge)
- DNS Error for Secure Web Sites only (Web Browsers)
- I cannot access any secure web sites (Web Browsers)
- Cannot Access a Single WEB Site (Web Browsers)
- Web server at home - ethernet router (Windows Servers and IIS)
Other Threads in the PHP Forum
- Previous Thread: PhoneBook Script [Project]
- Next Thread: Images made from Blob are Cut Off
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary bounce broken cakephp checkbox class cms code codingproblem combobox cron curl database date display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla js limit link login loop mail menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote return script search server sessions smash sms soap source space sql syntax system table tutorial up-to-date update upload url validation validator variable video web webapplications websitecontactform xml youtube





