base64 encoding a replace string

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

    base64 encoding a replace string

    I've got the example below to set up phpOpenTracker to log exit URL's
    but I'm having trouble getting it to work. I have played with the
    quotes and changed the \\2 to $3 and got the url in there but I can't
    get it to base64 encode it.

    I'm new to PHP and any help on getting the encoding to work would be
    appreciated.

    <?php
    function encode_exit_url s($buffer) {
    return preg_replace(
    "#<a(.*)href=(\ "|')http://([^\"']+)(\"|')#isUm",
    '"<a href=\"exit.php ?url=".base64_e ncode(\'\\2\'). "\""',
    $buffer
    );
    }

    // start output-buffering
    ob_start('encod e_exit_urls');

    // main code of your script
    ?>
    --
    Regards - Rodney Pont
    The from address exists but is mostly dumped,
    please send any emails to the address below
    e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk


  • Daniel Tryba

    #2
    Re: base64 encoding a replace string

    Rodney Pont <spam07@infohit .fsnet.co.uk> wrote:[color=blue]
    > I'm new to PHP and any help on getting the encoding to work would be
    > appreciated.
    >
    > <?php
    > function encode_exit_url s($buffer) {
    > return preg_replace(
    > "#<a(.*)href=(\ "|')http://([^\"']+)(\"|')#isUm",
    > '"<a href=\"exit.php ?url=".base64_e ncode(\'\\2\'). "\""',
    > $buffer
    > );
    > }[/color]

    You'll have to use preg_replace_ca llback if you want to "do things" with
    the backreferences.

    --

    Daniel Tryba

    Comment

    • Rodney Pont

      #3
      Re: base64 encoding a replace string

      On Thu, 23 Oct 2003 12:05:13 +0000 (UTC), Daniel Tryba wrote:
      [color=blue]
      >Rodney Pont <spam07@infohit .fsnet.co.uk> wrote:[color=green]
      >> I'm new to PHP and any help on getting the encoding to work would be
      >> appreciated.
      >>
      >> <?php
      >> function encode_exit_url s($buffer) {
      >> return preg_replace(
      >> "#<a(.*)href=(\ "|')http://([^\"']+)(\"|')#isUm",
      >> '"<a href=\"exit.php ?url=".base64_e ncode(\'\\2\'). "\""',
      >> $buffer
      >> );
      >> }[/color]
      >
      >You'll have to use preg_replace_ca llback if you want to "do things" with
      >the backreferences.[/color]

      I'm putting this before any output from HTML and it is changing the URL
      but not doing a base64 encode on it. Should the base64 encode be done
      when it does the replacement or is that something done by the browser
      when it goes to the link?

      I've tried <a href="exit.php? url=.base64_enc ode('the_link_u rl').">
      directly in the link so I don't think the browser does it.

      The problem is that I have some links to Google articles and unless I
      encode them exit.php sees them as parameters to it and not to Google.

      I've given up on this for the site, I'm base64 encoding the URL and
      pasting it into the href, but I'm interested in how this is supposed to
      work. I can't find any info on base64_encode being embedded in a string
      in the PHP manual.

      --
      Regards - Rodney Pont
      The from address exists but is mostly dumped,
      please send any emails to the address below
      e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk


      Comment

      • Daniel Tryba

        #4
        Re: base64 encoding a replace string

        Rodney Pont <spam07@infohit .fsnet.co.uk> wrote:[color=blue][color=green][color=darkred]
        >>> <?php
        >>> function encode_exit_url s($buffer) {
        >>> return preg_replace(
        >>> "#<a(.*)href=(\ "|')http://([^\"']+)(\"|')#isUm",
        >>> '"<a href=\"exit.php ?url=".base64_e ncode(\'\\2\'). "\""',
        >>> $buffer
        >>> );
        >>> }[/color]
        >>
        >>You'll have to use preg_replace_ca llback if you want to "do things" with
        >>the backreferences.[/color][/color]
        [snip][color=blue]
        > I've given up on this for the site, I'm base64 encoding the URL and
        > pasting it into the href, but I'm interested in how this is supposed to
        > work. I can't find any info on base64_encode being embedded in a string
        > in the PHP manual.[/color]

        Have you actually read my posting? You have to use preg_replace_ca llback()
        http://php.net/preg_replace_callback instead of preg_replace()

        It takes a funtion instead of a string. That function should return the
        a/href with the backreference 2 base64 encoded.

        --

        Daniel Tryba

        Comment

        • Rodney Pont

          #5
          Re: base64 encoding a replace string

          On Fri, 24 Oct 2003 11:39:15 +0000 (UTC), Daniel Tryba wrote:
          [color=blue][color=green][color=darkred]
          >>>> <?php
          >>>> function encode_exit_url s($buffer) {
          >>>> return preg_replace(
          >>>> "#<a(.*)href=(\ "|')http://([^\"']+)(\"|')#isUm",
          >>>> '"<a href=\"exit.php ?url=".base64_e ncode(\'\\2\'). "\""',
          >>>> $buffer
          >>>> );
          >>>> }
          >>>
          >>>You'll have to use preg_replace_ca llback if you want to "do things" with
          >>>the backreferences.[/color][/color]
          >[snip][color=green]
          >> I've given up on this for the site, I'm base64 encoding the URL and
          >> pasting it into the href, but I'm interested in how this is supposed to
          >> work. I can't find any info on base64_encode being embedded in a string
          >> in the PHP manual.[/color]
          >
          >Have you actually read my posting? You have to use preg_replace_ca llback()
          >http://php.net/preg_replace_callback instead of preg_replace()
          >
          >It takes a funtion instead of a string. That function should return the
          >a/href with the backreference 2 base64 encoded.[/color]

          I did read your posting Daniel. I looked up preg_replace_ca llback but I
          didn't understand how to create a function that could replace the
          a/href base64 encoded.

          Having had another look I think the light is beginning to dawn. If I
          understand it correctly all I have to do with the function is do a
          base64 encode on the third subpattern match, add the bits I want on and
          return it.

          I don't have output buffering on the host so I'm having to turn it on
          to create a session cookie and then turn it off. This works fine with
          Apache here but inserts a blank line with IIS on the host when I turn
          it off and flush, this isn't helping with the formatting :-)

          Thanks for your help and patience.

          --
          Regards - Rodney Pont
          The from address exists but is mostly dumped,
          please send any emails to the address below
          e-mail ngps07 (at) infohit (dot) fsnet (dot) co (dot) uk


          Comment

          • Daniel Tryba

            #6
            Re: base64 encoding a replace string

            Rodney Pont <spam07@infohit .fsnet.co.uk> wrote:[color=blue][color=green]
            >>Have you actually read my posting? You have to use preg_replace_ca llback()
            >>http://php.net/preg_replace_callback instead of preg_replace()
            >>
            >>It takes a funtion instead of a string. That function should return the
            >>a/href with the backreference 2 base64 encoded.[/color]
            >
            > I did read your posting Daniel. I looked up preg_replace_ca llback but I
            > didn't understand how to create a function that could replace the
            > a/href base64 encoded.
            >
            > Having had another look I think the light is beginning to dawn. If I
            > understand it correctly all I have to do with the function is do a
            > base64 encode on the third subpattern match, add the bits I want on and
            > return it.[/color]

            :) The online manual sometimes needs to be read more than once...
            [color=blue]
            > I don't have output buffering on the host so I'm having to turn it on
            > to create a session cookie and then turn it off. This works fine with
            > Apache here but inserts a blank line with IIS on the host when I turn
            > it off and flush, this isn't helping with the formatting :-)[/color]

            Hmmm, have you taken a look in the bug database? Sounds weird.

            --

            Daniel Tryba

            Comment

            Working...