GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-19-2007
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default ereg? Anti-Spam help!

I am using a php form processor and would like to stop web addresses from being input into the text fields.

A couple examples of what I have in place and general syntax:

PHP Code:
if (strlen($_POST['comments']) > 255 )
{
header("Location: http://www.websitename.com/error.php");
exit;
}
if (! 
ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+'$_POST['vis_email']))
{
header("Location: http://www.websitename.com/error.php");
exit;

I've tried a couple of different things (which I haven't added above) but can't seem to get the right combination of single quotes, quotes, or brackets.
Any help would be GREATLY appreciated!!!!!!!!!!
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-19-2007
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

I've got this working:
PHP Code:
/*ANTISPAM WEBSITES*/
if (ereg('^www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
{
header("Location: http://www.website.com/error.php");
exit;
}
if (
ereg('^[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
{
header("Location: http://www.website.com/error.php");
exit;
}
if (
ereg('^http\\:\\/\\/www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
{
header("Location: http://www.website.com/error.php");
exit;
}
if (
ereg('^http\\:\\/\\/[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
{
header("Location: http://www.website.com/error.php");
exit;

How would I shorten this?
__________________
Thank you,
Lynne Hanson
RL Hanson-Online
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-19-2007
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

PHP Code:
/*ANTISPAM WEBSITES*/
if (ereg('^www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
 
$skipit=1;
if (
ereg('^[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
 
$skipit=1;
if (
ereg('^http\\:\\/\\/www\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
 
$skipit=1;
if (
ereg('^http\\:\\/\\/[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments']))
 
$skipit=1;
if (
$skipit) {
 
header("Location: http://www.website.com/error.php");
 exit;

The above shortens by using a flag if there is a match and redirecting in one place. This way if you change the error page it only happens in one place.

Note also I am using the short version of IF, where if you only execute ONE command, you dont need the brackets.

Shortening the REGEX -
PHP Code:
if (ereg('^[http\\:\\/\\/]*[www\\.]*[A-Za-z0-9_-]+\\.[A-Za-z0-9]+'$_POST['comments'])) 
I think this should work. Note the brackets. By putting a * after instead of + you indicate that it is an optional match.
Note, the ^ means search from the beginning of the comments field, so if the URL is not the first thing in comments, it will pass, so I am not sure you want it in there.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-19-2007
rlhanson's Avatar
Master Glow Jedi
 
Join Date: Aug 2007
Location: Chapman, Kansas
Posts: 347
Rep Power: 35
rlhanson will become famous soon enough
Default

John-Marc!!!!!!!!!!!! Welcome back!

Thanks for the help - I'm trying this now.

Update: Your a gem - it works GREAT! Thank you so much!
__________________
Thank you,
Lynne Hanson
RL Hanson-Online

Last edited by rlhanson; 10-19-2007 at 10:32 AM. Reason: updating info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:08 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com