Jump to content

Match word.word?


LemonInflux

Recommended Posts

I'm in a situation where I get the user's desired page via a $_GET variable. The only problem is that, of course, this means that they could quite easily use directory traversal to view pages they shouldn't be able to. What I want is to check that the user's page doesn't contain anything but letters/numbers and a '.' in the middle, e.g. folder.file, but not folder.../file

 

I've been looking at various sites, and I came to ([A-Za-z0-9-]+)\.([A-Za-z0-9-]+)

Is this ok? Also, is there any way of shortening it? I know you can use \w to match words, but these don't contain numbers right?

Thanks in advance

 

----------------

Now playing: Dance Gavin Dance - It's Safe to Say You Dig the Backseat

via FoxyTunes

Link to comment
Share on other sites

Typically ^ and $ are used to anchor the beginning and end of the line, respectively; however these are affected by multi-line mode (/m). The other options are:

 

\A -- Same as ^, but not affected by multi-line mode.

\Z -- Same as $, but not affected by multi-line mode. May match before a string-ending new line.

\z -- Same as $, but not affected by multi-line mode. Will only match the end of the string.

 

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.