Regular Expression Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DjDrakk

    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("htt p://fakeaddress\.sy tes\.net/pillowtalk/order\.php(\?pr ob=[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



  • matty

    #2
    Re: Regular Expression Error

    DjDrakk wrote:
    [color=blue]
    > preg_match("htt p://fakeaddress\.sy tes\.net/pillowtalk/order\.php(\?pr ob=[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[/color]

    You haven't got any delimiters in your regexp.

    Try this:

    Comment

    • DjDrakk

      #3
      Re: Regular Expression Error

      "matty" <matt+nntp@askm enoquestions.co .uk> wrote in message
      news:wYR%a.8103 $z7.891502@ward s.force9.net...[color=blue]
      > DjDrakk wrote:
      >[color=green]
      > >[/color][/color]
      preg_match("htt p://fakeaddress\.sy tes\.net/pillowtalk/order\.php(\?pr ob=[0-4[color=blue][color=green]
      > > ])?", $_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[/color][/color]
      wrong?[color=blue][color=green]
      > > Thanks[/color]
      >
      > You haven't got any delimiters in your regexp.
      >
      > Try this:[/color]

      Try what? Your message got clipped.


      Comment

      • Andy Hassall

        #4
        Re: Regular Expression Error

        On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk" <DjDrakk@drakkr adio.servemp3.c om>
        wrote:
        [color=blue]
        >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("ht tp://fakeaddress\.sy tes\.net/pillowtalk/order\.php(\?pr ob=[0-4
        >])?", $_SERVER['HTTP_REFERER'])[/color]

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

        --
        Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
        Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

        Comment

        • DjDrakk

          #5
          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" <andy@andyh.co. uk> wrote in message
          news:c1rvjvs3vg 9fcl0fkstejk9d2 adam38bsg@4ax.c om...[color=blue]
          > On Sun, 17 Aug 2003 14:32:04 -0600, "DjDrakk"[/color]
          <DjDrakk@drakkr adio.servemp3.c om>[color=blue]
          > wrote:
          >[color=green]
          > >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[/color][/color]
          field[color=blue][color=green]
          > >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[/color][/color]
          field[color=blue][color=green]
          > >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[/color][/color]
          lots[color=blue][color=green]
          > >of tutorials for regular expressions in Perl, but none of them seem to[/color][/color]
          cross[color=blue][color=green]
          > >over properly to PHP, or at least for what i need. I have the following
          > >code....
          > >[/color]
          >
          >preg_match("ht tp://fakeaddress\.sy tes\.net/pillowtalk/order\.php(\?pr ob=[0-[/color]
          4[color=blue][color=green]
          > >])?", $_SERVER['HTTP_REFERER'])[/color]
          >
          > There's already a built-in function for this:[/color]
          http://uk2.php.net/parse_url[color=blue]
          >
          > --
          > Andy Hassall (andy@andyh.co. uk) icq(5747695) (http://www.andyh.co.uk)
          > Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]


          Comment

          • matty

            #6
            Re: Regular Expression Error

            DjDrakk wrote:
            [color=blue]
            > Ah, thanks, but I could still use a pointer to a good regex tutorial for
            > PHP.
            >[/color]

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

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

            but yes, parse_url is better!

            Comment

            Working...