473,226 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}

// start output-buffering
ob_start('encode_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
Jul 17 '05 #1
5 25590
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
I'm new to PHP and any help on getting the encoding to work would be
appreciated.

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


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

--

Daniel Tryba

Jul 17 '05 #2
On Thu, 23 Oct 2003 12:05:13 +0000 (UTC), Daniel Tryba wrote:
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
I'm new to PHP and any help on getting the encoding to work would be
appreciated.

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


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


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_encode('the_link_url'). ">
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
Jul 17 '05 #3
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}
You'll have to use preg_replace_callback if you want to "do things" with
the backreferences.

[snip] 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.


Have you actually read my posting? You have to use preg_replace_callback()
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

Jul 17 '05 #4
On Fri, 24 Oct 2003 11:39:15 +0000 (UTC), Daniel Tryba wrote:
<?php
function encode_exit_urls($buffer) {
return preg_replace(
"#<a(.*)href=(\"|')http://([^\"']+)(\"|')#isUm",
'"<a href=\"exit.php?url=".base64_encode(\'\\2\')."\""' ,
$buffer
);
}

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

[snip]
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.


Have you actually read my posting? You have to use preg_replace_callback()
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.


I did read your posting Daniel. I looked up preg_replace_callback 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
Jul 17 '05 #5
Rodney Pont <sp****@infohit.fsnet.co.uk> wrote:
Have you actually read my posting? You have to use preg_replace_callback()
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.
I did read your posting Daniel. I looked up preg_replace_callback 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.


:) The online manual sometimes needs to be read more than once...
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 :-)


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

--

Daniel Tryba

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mvdevnull | last post by:
hey all currently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
2
by: kevin | last post by:
DISCLAIMER: I know what the words mean (i.e. by definition), but I in know way pretend to understand the specifics of either, therefore I may need a basic primer before I can accomplish this task,...
3
by: mm | last post by:
Hello everyone, I have an asp.net application executing under .net framework 1.1 that sends a base64 encoded string token to a remote server running weblogic application server. for some odd...
3
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out...
5
by: Jay | last post by:
I have bean trying to get my head around reading .GIF files from base64 strings, Basically I need to specify a filename and convert it to base64 then I can copy/past the string to wear I want it....
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
13
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or...
10
by: pycraze | last post by:
Hi , I am currently trying to implement base64 encoding and decoding scheme in C . Python has a module , base64 , that will do the encoding and decoding with ease . I am aware of OpenSSL having...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.