Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Please Help (php Join Script)
sparkx
post May 23 2007, 11:25 PM
Post #1


Sparkx
Group Icon

Group: [HOSTED]
Posts: 343
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



Ok as you all know by now I have been working on a php based game to help me learn php. It has been going great and it is almost done. I got some 
very good help on issues here and along with sites like php.net. However I am stuck and can not find a solution to a problem anywere.
My Problem: I want users to join but I don't want some charicters to be in there name (example I dont want < so the name '<Test' would come back as an error). Anyway I see a lot of sites that check for this and I know you can check for it in javascript but I want to use php to do it because php is more secure. I have tried lots of things like strstr ect and they don't seem to work with what I want. Anouther variable that comes into play is that I want it to check an array. Here is an example.
Disallowed Charicters: <, >, ', "
I would array like:
CODE
$string = array(<, >, ', ");

This for some reason does not work for.
CODE
if(strpos($name, $string)){
//error stuff here
exit();
}

Do you get what I am saying anyone? This simply essures that noone adds html ect to there name.
Thanks for the help,
Sparkx

This post has been edited by sparkx: May 23 2007, 11:26 PM
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post May 24 2007, 02:53 AM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



Shouldn't the values you're inserting into an array be enclosed to single/double quotes? For example, shouldn't this line...
CODE
$string = array(<, >, ', ");


be written like this ?
CODE
$string = array("<", ">", "'", "\"");


... but I may be mistaken.

However, keep in mind that strpos will return an INTEGER indicating the location of the first encountered "needle" in the "haystack". Dunno if an if{} statement can interpret a if(strpos()) correctly. What I know is that, when the search string isn't found, strpos() will return a boolean false. Maybe if you invert the code-logic, it'll work. Example..
CODE
if( strpos($name, $string) === false )
{ // Do nothing }
else {

// error stuff

}


Note that a boolean comparison is done using THREE '=' signs as compared to other types of equivalence match, where TWO or '=' are used.

Otherwise I see no problem with your logic. It should work out fine.

On a side-note, why do you want PHP to validate the character's name? Think of it this way - if you use PHP, it'll involve an extra client >> server >> client data transmission cycle, before the user gets to know about the problems in the name. In comparison, if you use JavaScript for validation - the name is checked in situ.. i.e. right inside your browser and the page is never submitted to the server till the user has got it all right. From the point of efficiency, this is a far better approach as it uses your local CPU to perform these mundane tasks rather than putting some extra load on the server.
Go to the top of the page
 
+Quote Post
sparkx
post May 24 2007, 10:13 PM
Post #3


Sparkx
Group Icon

Group: [HOSTED]
Posts: 343
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



That is true about the server, however what if they turn of php. Here are some ideas I have but I am not sure if they will work effectivly. Would you look them over?
A: Put both so if the javascript works then the php checks. This will provent people from copying my page, editing my javascrpt and resubmitting or even turning of javascript period.
B: Is there a way to check what url a form came from. I could check the url and make sure it is my url essuring that the above doesn't happen.
C: I was woundering rather stop some charicters I should only allow others like A-Z, a-z and a few others like _ that would be easier then just finding all the charectors that do not work.
If you know how I could do any of the above or if you have other ideas please post them. Everything is welcome and appriciated.
Thanks,
Sparkx
Go to the top of the page
 
+Quote Post
Quatrux
post May 25 2007, 04:31 AM
Post #4


the Q
Group Icon

Group: [HOSTED]
Posts: 1,022
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



If you only want to allow A-Z,a-z,0-9 in the username, when you can make a check using regular expression, you really will find examples on php net comments of such functions like preg_replace() and preg_match(), another way to do it is by using ctype here: http://lt.php.net/ctype just check what you want to filter. wink.gif
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post May 25 2007, 04:51 AM
Post #5


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



I have a script (JS) that allows you to effectively filter out keystrokes.. i.e. if you allow only { A-Z, a-z, 0-9 }, the input field will not accept any keystrokes other than those... that might help you somewhat. If you need it let me know and I'll post it here.
Go to the top of the page
 
+Quote Post
sparkx
post May 28 2007, 01:01 AM
Post #6


Sparkx
Group Icon

Group: [HOSTED]
Posts: 343
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



Thank you both for the help. Right now I am using both. First javascript but if the person has javascript disabled then it uses php to check it. I can't remember the exact code off hand but it was something like this:
CODE
if(preg_match(...

Well anyway it worked. Thanks Quatrux. I just want to ask one quick question before this topic gets closed.
Is it possible to check where a form came from? I am not using it as a "Secure" way to check (because I know you can edit and run the source of a page quite easyly) but rather a log, to see if any website are submitting forms to my php. If there is a way could you link me to the code or tell me the fuction at least?
Thank you very much for the help. I am getting more and more of this php stuff down,
Sparkx
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Make A Text Based Online Game Script ?(23)
  2. PHP: Writing A Generic Login And Register Script(14)
  3. Php Script To Download File From Another Site(9)
  4. Coppermine Random Image Script(6)
  5. How To Save A Image In Pdf File And Download It?(10)
  6. Bash Script To Display Your Ip(9)
  7. Help Needed To Create Login Script With Perl/cgi(21)
  8. How Can I Create A "number Of Visitors" Script(8)
  9. Need Help With A PHP - MySQL Registration Script(13)
  10. Free Private Sever For Ragnarok Online(4)
  11. PHP Tutorial: Form Verification And Simple Validation(12)
  12. Create And Import JavaScript Modules For A Large Script(2)
  13. Running Vba Script In Excel(6)
  14. Help Needed To Create Windows Startup Script!(4)
  15. Rpg For (php)wml Script Text Based(1)
  1. Very Simple Login-script(18)
  2. Attack Script In Php(5)
  3. A Simple Register Script(3)
  4. Auto-click Script(7)
  5. Script Request(2)
  6. Love Script(3)
  7. Myspace Gold Script(2)
  8. Looking For Script(5)
  9. Free Login Script(1)
  10. Php Login Script(0)
  11. Alluraro(1)
  12. Creating A Php Login Script(3)
  13. Myspacetv Download Php Script Help(6)


 



- Lo-Fi Version Time is now: 7th September 2008 - 01:40 AM