Jump to content

Recommended Posts

I've got a php guestbook which i built myself and it works fine.
But I've got idiots going on there and they just keep putting links within their messages
advertising their own sites which is very annoying.
Is there a way to stop this by not allowing certain characters, for example '<' or '>'
cheers in advance
Link to comment
https://forums.phpfreaks.com/topic/3579-stop-users-putting-links-in-my-guestbook/
Share on other sites

you could search the posted variable for invalid characters?


[code]

foreach (count_chars($your_posted_variable, 1) as $i) {
$string=chr($i);
if ($string=="&"){
echo "You cannot use that character";
}

[/code]

the above code will search your posted variable for '&'. If this character is found, an error message is displayed. I havent tried the code but I think the syntax is correct (ive just woken up..lol)

Hope this helps
  • 1 month later...
I am a total newbie and got a finished script for my guestbook. Recently I´ve started to get problems with people spamming my guestbook, so I´d like to use this string you´ve written in this thread. But when I tried to copy it into my guestbook it siezed to work at all. Any idea where in the script i should put the string in order to getting it work?

The URL to my guestbook is [a href=\"http://www.themovements.com/guestshow.php\" target=\"_blank\"]http://www.themovements.com/guestshow.php[/a]

Thanks
/Gustaf
I suggest looking for url's in the posted variables, this will do:

[code]
<?

$content = $_POST['message_body']; // or whatever

$url_match = "^(((http|ftp|https)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&%_\./-~-]*)?^";

if (preg_match($url_match, $content))
{
echo "A url was found in your post, Not allowed - mission aborted.";
exit ();
}
else
{
// continue with submission here, no url found


}

?>
[/code]

And to RedAlert, you must post a code in order for anyone to help you out on why it stopped working...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.