By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

Regular Expression Error

P: n/a
I want to use headers to redirect the client if they didn't come from the
correct page, but I have a problem with one page. If they leave a form field
empty, they are redirected back to the page they came from with an error
number and a 6 digit 1d number in the location bar which defines what field
was left empty( order.php?prob=2&id=000001)

My only problem is that when they repost, the $_SERVER['HTTP_REFERER']
contains the get variables and doesn't match, so they get redirected.
Instead of coding an if statement for every possible combination of error
numbers and ids, I decided it would be faster to use regular expressions.
This is the first time I've ever used regular expressions. I've found lots
of tutorials for regular expressions in Perl, but none of them seem to cross
over properly to PHP, or at least for what i need. I have the following
code....

preg_match("http://fakeaddress\.sytes\.net/pillowtalk/order\.php(\?prob=[0-4
])?", $_SERVER['HTTP_REFERER'])

which keeps on returning "Warning: Delimiter must not be alphanumeric or
backslash in line 2"
I was wondering if anybody knows of a good place to learn how to use regular
expressions in PHP, or if you could tell me what I'm doing wrong? Thanks
--

Warren
-- Custom web design, cheap like cheese

Jul 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
DjDrakk wrote:
preg_match("http://fakeaddress\.sytes\.net/pillowtalk/order\.php(\?prob=[0-4
])?", $_SERVER['HTTP_REFERER'])

which keeps on returning "Warning: Delimiter must not be alphanumeric or
backslash in line 2"
I was wondering if anybody knows of a good place to learn how to use
regular expressions in PHP, or if you could tell me what I'm doing wrong?
Thanks


You haven't got any delimiters in your regexp.

Try this:
Jul 16 '05 #2

P: n/a
"matty" <ma*******@askmenoquestions.co.uk> wrote in message
news:wY******************@wards.force9.net...
DjDrakk wrote:
preg_match("http://fakeaddress\.sytes\.net/pillowtalk/order\.php(\?prob=[0-4 ])?", $_SERVER['HTTP_REFERER'])

which keeps on returning "Warning: Delimiter must not be alphanumeric or
backslash in line 2"
I was wondering if anybody knows of a good place to learn how to use
regular expressions in PHP, or if you could tell me what I'm doing wrong? Thanks


You haven't got any delimiters in your regexp.

Try this:


Try what? Your message got clipped.
Jul 16 '05 #3

P: n/a
On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk" <Dj*****@drakkradio.servemp3.com>
wrote:
I want to use headers to redirect the client if they didn't come from the
correct page, but I have a problem with one page. If they leave a form field
empty, they are redirected back to the page they came from with an error
number and a 6 digit 1d number in the location bar which defines what field
was left empty( order.php?prob=2&id=000001)

My only problem is that when they repost, the $_SERVER['HTTP_REFERER']
contains the get variables and doesn't match, so they get redirected.
Instead of coding an if statement for every possible combination of error
numbers and ids, I decided it would be faster to use regular expressions.
This is the first time I've ever used regular expressions. I've found lots
of tutorials for regular expressions in Perl, but none of them seem to cross
over properly to PHP, or at least for what i need. I have the following
code....

preg_match("http://fakeaddress\.sytes\.net/pillowtalk/order\.php(\?prob=[0-4
])?", $_SERVER['HTTP_REFERER'])


There's already a built-in function for this: http://uk2.php.net/parse_url

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #4

P: n/a
Ah, thanks, but I could still use a pointer to a good regex tutorial for
PHP.

--

Warren Butt
-- Custom web design, cheap like cheese
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:c1********************************@4ax.com...
On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk" <Dj*****@drakkradio.servemp3.com> wrote:
I want to use headers to redirect the client if they didn't come from the
correct page, but I have a problem with one page. If they leave a form fieldempty, they are redirected back to the page they came from with an error
number and a 6 digit 1d number in the location bar which defines what fieldwas left empty( order.php?prob=2&id=000001)

My only problem is that when they repost, the $_SERVER['HTTP_REFERER']
contains the get variables and doesn't match, so they get redirected.
Instead of coding an if statement for every possible combination of error
numbers and ids, I decided it would be faster to use regular expressions.
This is the first time I've ever used regular expressions. I've found lotsof tutorials for regular expressions in Perl, but none of them seem to crossover properly to PHP, or at least for what i need. I have the following
code....

preg_match("http://fakeaddress\.sytes\.net/pillowtalk/order\.php(\?prob=[0-

4
])?", $_SERVER['HTTP_REFERER'])


There's already a built-in function for this:

http://uk2.php.net/parse_url
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

Jul 16 '05 #5

P: n/a
DjDrakk wrote:
Ah, thanks, but I could still use a pointer to a good regex tutorial for
PHP.


Wrap your regex in (e.g.) # chars
e.g. preg_match('#some(stuff)?#'...
or '/some(stuff)?/'

i like # becuase then it makes it easier to have '/' in the expression...

but yes, parse_url is better!
Jul 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.