Jump to content

can someone check this for me


chris_s_22

Recommended Posts

both of these are suposed to check url is in correct format?

 

this should only alow http:// with domain name

with no folder extentions

if(!preg_match("/^http://[0-9a-zA-Z-.].[a-zA-Z]{2,3}$/", $_POST[linkto]))

 

this should alow as above but with folder ext

if(!preg_match("/^http://(www.[0-9a-zA-Z][0-9a-zA-Z-][0-9a-zA-Z]|[0-9a-zA-Z][0-9a-zA-Z-][0-9a-zA-Z]).[a-zA-Z]{2,3}[0-9a-zA-Z/-_.]$/", $_POST[linkfrom]))

 

Link to comment
Share on other sites

I'm not entirely sure what your question is so I'm going to go ahead and just make some general comments.

 

1). $_POST[linkto] will (probably) throw a Notice level error. You should really change this to $_POST['linkto'].

2). Your pattern has no repeat metacharacter/sequence for the first character set meaning it will only match against a single character.

3). You then have an unescaped period/fullstop which will allow any single character.

4). You use your delimiter character in your pattern without escaping it.

5). 2 to 3 characters for the top level domain will not allow for urls such as http://something.info, which is a valid URL.

6). By using the exclamation mark, the if statement will only be entered if the string entered doesn't match the pattern.

Link to comment
Share on other sites

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.