/    Sign up×
Community /Pin to ProfileBookmark

in just a few weeks, it is unstopable [PHP,MySQL database]security

hi! I started learning PHP and MySQL database a few months ago and came up with this [url]http://positive0.negative0.net/[/url]
.

I’m still learning. But the problem starts once I have my guestbook using PHP and MySQL running. See it for yourself. I would suggest not because it would take a few seconds to minutes to open up the page [url]

According to some in the forum, there are bugs and security hole. I’ve been trying to solve but my efforts seems like a waste of time because the posts kept increasing. And I think the codes are correct.

These are my 2 scripts,

guesth_postie.php

[code=php]

<?php
//Connects to your Database
$connect = mysql_connect(“localhost”, “user”, “password”) or die(mysql_error());
mysql_select_db(“db”);

$query = “SELECT * FROM db order by no desc “;
$result = mysql_query ($query, $connect);
Print “<table border=0 cellpadding=0 width=400 height=* cellpadding=0>”;

Print “<tr>”;
Print “<tr><td align=left>Name</td><td>Monkeyhead</td></tr> “;
?>
<tr><td align=”left”>Email</td><td>
<a href=”mailto:[email protected]”>[email protected]</a></td>
</tr>
<?
Print “<tr><td align=left>Website</td><td>http://positive0.negative0.net</td></tr>”;
Print “<tr><td align=left>Subject</td><td>Welcome</td></tr>”;
Print “<tr><td valign=top align=center>Message&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align=top width=400>
Welcome to the monkeyhead message board. Enjoy!</td></tr>”;

Print “<tr><td><hr></td><td width=350><hr></td></tr>”;
Print “<tr>”;

while($info = mysql_fetch_array( $result ))
{
Print “<tr>”;
Print “<tr><td align=left>Name</td><td> “.$info[‘name’] . “</td></tr> “;
?>
<tr><td align=”left”>Email</td><td><a href=”mailto:<?=$info[’email’]?>”>
<?=$info[’email’]?></a></td>
</tr>
<?
Print “<tr><td align=left>Website</td><td>”.$info[‘website’] . “</td></tr>”;
Print “<tr><td align=left>Subject</td><td>”.$info[‘subject’] . “</td></tr>”;
Print “<tr><td valign=top align=center>Message&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align=top width=400>”.$info[‘message’] . “</td></tr>”;

Print “<tr><td><hr></td><td width=350><hr></td></tr>”;
Print “<tr>”;
}
Print “</table>”;

mysql_close($connect);
?>
[/code]

And the input file
input.php

[code=php]
<?php

function noblank($msg){
echo ”
<script>
window.alert(‘$msg’);
history.back(1);
</script>
“;
exit;
}
if(!$name) noblank(‘Please write your name’);
if(!$subject) noblank(‘Please write your subject and message’);
if(!$message) noblank(‘Please write your message’);

// Connects to your Database

$connect = mysql_connect(“localhost”, “user”, “password”) or die(mysql_error());
mysql_select_db(“db”) or die(mysql_error());
$query = “INSERT INTO db (no, name, website, subject, message, email, regdate, ip)
values (‘no’,’$name’,’$website’,’$subject’,’$message’,’$email’, now(),’$REMOTE_ADDR’)”;

mysql_query ($query, $connect);

mysql_close($connect);
?>
[/code]

I don’t want to cause any harm to the one that is causing this problem but I just want to find out “how I can possibly fix it” and prevent this kind of mistake.
I would appreciate it very much!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 20.2006 — You probably need to implement a "captcha" graphic and input field on your form to prevent automated scripts from making submissions to your site.
Copy linkTweet thisAlerts:
@TaschenSep 20.2006 — I believe the expression is OMG! Using an image captcha might stop some automated posting (OCR anyone) but won't close that immense whole in your script.

It is absolutely crucial that you at least validate any user input, especially before posting to a db.

Validating user input means posting to some kind of processing script that strips out escaped php/SQL, html and java.

I recommend that you visit www.php.net to learn about the different functions available.
Copy linkTweet thisAlerts:
@chazzySep 20.2006 — also, your no blank script only works in javascript is disabled.

you should have a marker saying whether there is a problem w/ the items and no do the db insert if that's the case.
×

Success!

Help @Michaelttkk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...