943,589 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1565
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 16th, 2009
0

How to secure my web

Expand Post »
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.
Similar Threads
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Aug 16th, 2009
0

Re: How to secure my web

mysql_real_escape_string()
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Aug 16th, 2009
0

Re: How to secure my web

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.
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Aug 18th, 2009
0

Re: How to secure my web

thankx guys for replying))
i added the following in my login form.
php Syntax (Toggle Plain Text)
  1. $user=mysql_real_escape_string($_POST['user']);
  2. $password=mysql_real_escape_string(md5($_POST['password']));
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.??
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Aug 18th, 2009
0

Re: How to secure my web

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:
PHP Syntax (Toggle Plain Text)
  1. echo md5("password here");
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 mysql_real_escape_string() a string that you pass it through stripslashes:
PHP Syntax (Toggle Plain Text)
  1. $user = mysql_real_escape_string(stripslashes($_POST['user']));
  2. $password = mysql_real_escape_string(stripslashes($_POST['password']));
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.
Last edited by FlashCreations; Aug 18th, 2009 at 3:47 pm.
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Aug 18th, 2009
0

Re: How to secure my web

@FlashCreations,in da web when registering i hash the passwords with md5().thats why when login i was using
php Syntax (Toggle Plain Text)
  1. $user=$_POST['user'];
  2. $password=md5($_POST['password']);
the problem started after i added
php Syntax (Toggle Plain Text)
  1. mysql_real_escape_string
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
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Aug 18th, 2009
0

Re: How to secure my web

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.
Reputation Points: 47
Solved Threads: 47
Posting Whiz
FlashCreations is offline Offline
393 posts
since Sep 2008
Aug 19th, 2009
0

Re: How to secure my web

here is my login code
php Syntax (Toggle Plain Text)
  1. <?php session_start();
  2.  
  3. $user=mysql_real_escape_string($_POST['user']);
  4. $password=mysql_real_escape_string(md5($_POST['password']));
  5.  
  6.  
  7. //connecting to databases
  8. include"config.php";
  9.  
  10.  
  11.  
  12. $query = "SELECT *FROM login where (user='$user' and password='$password')" ;
  13. $result=mysql_query($query);
  14. if(mysql_num_rows($result)==1) {
  15.  
  16. $row=mysql_fetch_array($result);
  17. $id=$row['id'];
  18. $user=$row['user'];
  19. $password=$row['password'];
  20. $email=$row['email'];
  21.  
  22. $_SESSION['id']=$row['id'];
  23. $_SESSION['user']=$row['user'];
  24. $_SESSION['password']=$row['password'];
  25. $_SESSION['email']=$row['email'];
  26. $_SESSION['name']=$row['name'];
  27. $_SESSION['photo']=$row['photo'];
  28.  
  29. include "index.php";
  30.  
  31.  
  32. }else{
  33. include"wronglogin.php";
  34. }
  35.  
  36. ?>
]
Reputation Points: 17
Solved Threads: 8
Posting Whiz in Training
mrcniceguy is offline Offline
278 posts
since Mar 2008
Aug 19th, 2009
0

Re: How to secure my web

yes that is also a corect statement but u also need to do this for the registration as well because it is actually inserting into the database there is more of a risk
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009
Aug 19th, 2009
0

Re: How to secure my web

Your code is looking fine. Do you have any issue?
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PhoneBook Script [Project]
Next Thread in PHP Forum Timeline: Images made from Blob are Cut Off





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC