Professional Web Applications Themes

Regular Expression Error - PHP Development

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, ...

  1. #1

    Default Regular Expression Error

    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



    DjDrakk Guest

  2. #2

    Default Re: Regular Expression Error

    "matty" <matt+nntpaskmenoquestions.co.uk> wrote in message
    news:wYR%a.8103$z7.891502wards.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.


    DjDrakk Guest

  3. #3

    Default Re: Regular Expression Error

    On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk" <DjDrakkdrakkradio.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: [url]http://uk2.php.net/p_url[/url]

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  4. #4

    Default Re: Regular Expression Error

    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" <andyandyh.co.uk> wrote in message
    news:c1rvjvs3vg9fcl0fkstejk9d2adam38bsg4ax.com...
    > On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk"
    <DjDrakkdrakkradio.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:
    [url]http://uk2.php.net/p_url[/url]
    >
    > --
    > Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    > Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])

    DjDrakk Guest

  5. #5

    Default Re: Regular Expression Error

    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:
    matty Guest

  6. #6

    Default Re: Regular Expression Error

    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, p_url is better!
    matty Guest

Similar Threads

  1. Regular Expression
    By dj in forum PHP Programming
    Replies: 42
    Last Post: June 22nd, 08:47 AM
  2. help on regular expression
    By Madhu Reddy in forum PERL Beginners
    Replies: 5
    Last Post: January 28th, 01:31 AM
  3. regular expression - help
    By kaptain kernel in forum PHP Development
    Replies: 4
    Last Post: November 10th, 08:04 PM
  4. Regular Expression HELP!
    By jn in forum PHP Development
    Replies: 9
    Last Post: November 7th, 05:28 AM
  5. javascript regular expression error
    By T. Pastrana in forum Macromedia Dreamweaver
    Replies: 3
    Last Post: July 16th, 02:12 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139