473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

WIldcard to ban user from posting

4
Hello
Very new to php and I want to block a user from posting in my Joomla site (akocomment component).

The user ( a spammer ) uses John 12345 as the name of the poster and I just what to hardcode the block into the code. The numbers after John alters so I need some kind of wildcard to prevent the spamming.

Tried this
Expand|Select|Wrap|Line Numbers
  1. $banjohn = "John"*;
  2. if ($acname == $banjohn){
  3.     echo "No spamming allowed!";
  4.     exit;
but no go, the wildcard does not work, how would I go about to make it block the spammer?
Aug 26 '07 #1
7 1508
pbmods
5,821 Expert 4TB
Heya, mooler. Welcome to TSDN!

Try using strpos().
Aug 26 '07 #2
mooler
4
Thanks for the reply

Would that just exlude all posters named John?

ie.


[PHP]$findme = 'John';
if (strpos($acname, $findme) {
echo "You are blocked!";
exit;
}[/PHP]

Or am I misinterpreting the strpos manual? It's the numbers I'm after.

Or could it be done like this

[PHP]$1 = "1";
$2 = "2";
$3 = "3";
$4 = "4";
//and so on
$findme = 'John',$1,$2,$3,$4;
if (strpos($acname, $findme) {
echo "You are blocked!";
exit;
}[/PHP]
Aug 26 '07 #3
pbmods
5,821 Expert 4TB
Heya, Mooler.

If you want to block all posters whose name starts with 'John', you'd do this:
Expand|Select|Wrap|Line Numbers
  1. if( strpos($acname, 'John') === 0 )
  2. {
  3.     // Banned!
  4. }
  5.  
This checks to see if $acname starts with 'John' (i.e., if 'John' starts at position zero of $acname).

Note that we use '===' here. This is because if strpos() doesn't find the target string in $acname, it will return false, which will evaluate to zero. This is not desirable, but by using '===' instead of '==', we only display the block message if strpos() returns the integer 0.
Aug 26 '07 #4
mooler
4
Ok thanks agiain.
Yes I want to block all users named John but only if it is followed by a space ( " ") followed number ie. Johan 23543

[PHP]$findme = "John"+1||2||3||4||5||6||7||8||9||0;

if (strpos($acname, $findme) {
echo "You are blocked!";
exit;
}[/PHP]

This should check $acname for John in position 0 followed by a number (right?). And if that is true return the echo message? Any user just named "John" will return a false?
Or will it just check the caracter after the string "John" and therfor the code has to include a " " to get it right?
Like this:

[PHP]$findme = "John"+" "+1||2||3||4||5||6||7||8||9||0;[/PHP]

Sorry for beeing abit anoying but I'm trying to learn how to thing using php. And thanks again for your patience!
Aug 27 '07 #5
pbmods
5,821 Expert 4TB
Heya, Mooler.

Ah. I see what you're getting at now. For that, you'll probably want to use a regular expression.

You want to block a string that matches this pattern:
  1. Starts with 'john '
  2. Followed by one or more numbers.
  3. (and that's it)

Expressed as a regexp:
Expand|Select|Wrap|Line Numbers
  1. .  1    2 3
  2. /^john \d+$/i
  3.  
The 'i' makes it case-insensitive, so that it will match 'john 123', 'John 123' or even 'jOhN 654321'.

So how to integrate that into your code?
Expand|Select|Wrap|Line Numbers
  1. if( preg_match('/^john \\d+$/i', $acname) )
  2. {
  3.     echo 'Bl0x0ReD!';
  4.     exit;
  5. }
  6.  
For more info about regular expressions, check out this site.
Aug 27 '07 #6
mooler
4
Yes! That's it! Thank you very much will read up on regular expressions. Thanks again.
Aug 28 '07 #7
pbmods
5,821 Expert 4TB
Heya, Mooler.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 28 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Robert Brown | last post by:
I have researched newsgroups and the web very thoroughly and unsuccessfully for a solution to what I believe is a very common problem. I know it's easy to do wildcard match against data in DB...
12
by: Niall Porter | last post by:
Right this has to be a Micro$oft mess-up surely...? I'm running SQL 2k standard with SP3. I have a table which I'm trying to query using a LIKE operator on a varchar field as follows .......
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
3
by: Adam | last post by:
Its my understanding that in asp.net 2.0 you can write an httpmodule that will acts as a wildcard handler and pass requests on to the proper engine, for instance, asp or perl for example, In the...
2
by: Ken Yee | last post by:
First a little background: I've written an httphandler to handle wildcard extensions (i.e., I want to handle all URLs that come in rather than just URLs w/ a specific file extension so I can give...
2
by: Helen | last post by:
vb windows .net 200 crystal reports Record selection formula works fine for currency string result, good for operators =/>= and so on, as follows vb for Private Sub Button1_Click(ByVal sender...
2
by: Jan Kucera | last post by:
Hi, I have virtual MyFolder/* and MyFolder/MySubFolder/* mapped to an httphandler in the web.config file and all works perfectly on the asp.net development server. However on the IIS6/Win2003 I'm...
0
by: Gordon.E.Anderson | last post by:
short description: i've got a .net web site set up using a tableadapter attached to a sql server table - returning results only, no update of data. i've got a query (qry code below) set up to...
0
by: savage678 | last post by:
Hi Everyone, I am new to this forum and am i dire need of some help. I am trying to use wildcard searches in infopath. I have it connected to an access database using data connection. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.