Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check for string in part of a form

Status
Not open for further replies.

countrydj

ISP
Sep 27, 2002
21
GB
I have a form for adding a notice to a notice board which is passed to a perl script.
I am constantly being inundated with spam url links on a notice board which I want to stop.

Can anybody tell me how I can check the form $notice for the first occurance of http:// and https:// and www. In order to block these notices.

In PHP I can use:
$pos = strpos($notice, " if ($pos !== false) {
URLs not allowed ;
}

I now need to do the same thing in Perl.

Thanks,

John C
 
Hi feherke...
Boy !!! That was quick !!! Thanks very much...

I will need to test 3 or 4 strings.
e.g. http:\\ and www. and https\\

Can you tell me how to do this.

e.g.
$pos1 = strpos($notice, "$pos2 = strpos($notice, "$pos3 = strpos($notice, "
if (($pos1 < 0) or ($pos2 < 0) or ($pos3 < 0)) {
print "URLs not allowed" ;
}

I'm not sure what the operator is for 'or'.

Many thanks,

John C
 
Hi

countrydj said:
I'm not sure what the operator is for 'or'.
Then read about or in the manual. But that is Ok.

I would prefer checking that with regular expression :
Code:
print "URLs not allowed" if $notice=~m/https?:\/\/|[URL unfurl="true"]www/;[/URL]


Feherke.
 
Feherke said:
Code:
print "URLs not allowed" if $notice=~m/https?:\/\/|[URL unfurl="true"]www/;[/URL]

Definitely agree that pattern matching is better in this instance. However, slight cleanup of your code:

Code:
print "URLs not allowed" if $notice =~ m{https?://|[URL unfurl="true"]www\.}i;[/URL]

- Miller
 
Hi Guys..
Many thanks for taking the trouble to help me.
After all my tests I found that:
$pos = strpos($notice, "if ($pos < 0) {
print "Content-Type: text/html\r\n\r\n";
print "URLs not allowed" ;
}

didn't work. It just kept giving me a server error.

I used:
print "URLs not allowed" if $notice =~ m{https?://|www\.}i;
with a slight modification to:
if (($notice=~m/http:\/\//) || ($notice=~m/https:\/\//))

{
&no_url;
}

and this worked fine.
I then decided to try:
if ($notice =~ m{https?://| {
&no_url;
}

and I found that this worked even better, BUT I DON'T KNOW WHY.

I found that it trapped http; https; www. which is exactly what I wanted.
Can you tell me what all the operators do so that I can maybe get a better understanding.

Many thanks
 
Hi

Ooch ! In my first post I gave you correct URL to the manual but I forgot to use the referred function in the code too. Sorry.
Code:
$pos = [red]index[/red]($notice, "[URL unfurl="true"]http://");[/URL]

Feherke.
 
Hi Guys..
many thanks for your help and advise.
I will have a look at the documents when I get time, and try the revised code.

Thanks again...

John C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top