Forum Moderators: coopster

Message Too Old, No Replies

"Encrypting" urls

Trying to figure out how to encrypt urls for use with affiliate programs...

         

erikcw

2:21 am on Oct 21, 2004 (gmt 0)

10+ Year Member



Hi All,

I am trying to figure out how to use php to convert a string (a url) into html entities

Example:


http://ww&#1 19;.ebookwho lesaler.n et/r/g.ph&#1 12;?u=trimak mini
(broken up with spaces so that it will wrap in the window...)

I've tried a couple of functions, but they don't seem to yield the result I am looking for - they just produce codes for "special characters" - where I want the codes for all characters (including .,:,/,?)

Any ideas?

Thanks!

JamesRock

4:27 am on Oct 21, 2004 (gmt 0)

10+ Year Member



try this (or something similar):


$url = 'http://www.yahoo.com/?q=';
$url .= urlencode(serialize($data));

then at the recieving end:


$q = stripslashes(urldecode($_GET['q']));
$q = unserialize($q);

hope this helps

erikcw

9:59 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Gave that a try, but I didn't encode the entire URL.


$data = 'http://www.yahoo.com/?q=';
$url = urlencode(serialize($data));
echo $url;

Produced:
s%3A24%3A%22http%3A%2F%2Fwww.yahoo.com%2F%3Fq%3D%22%3B

http and www.yahoo.com were not encoded. I want the whole string to come out the other end encode in html entities.... Ideas?

jatar_k

10:45 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I found one online that I have been using for emails but it's js. I convert them and then just paste them in.

it is this

// speeds things up
d = document;

// our regexp for evaluating email addresses
var pattern = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,8}$/;

function init()
{
// get form objects
ascObj = d.getElementById("ascii");
uniObj = d.getElementById("unicode");
}

function obf() {
// get string (convert to lowercase)
s = ascObj.value.toLowerCase();

// find length of string
strLen = s.length;

// validate the email
noErrs = true;

if(strLen == 0) {
alert("You appear to have left the email address field blank. What's up with that?");
noErrs = false;
} else {
if(!pattern.test(s)) {
if (!confirm("Your entry, \""+s+"\", "+" does not appear to be a valid email address. Continue?")) {
noErrs = false;
}
}
}

// if it's a valid address, or they want to convert it anyway, then proceed
if (noErrs) {
// clear value of new string
newStr = "";

// loop through characters from last to first
for (i=strLen-1;i>-1;i--)
{
// build new string
newStr = "&#" + s.charCodeAt(i) + ";" + newStr;
}

// insert value for new email address
uniObj.value = newStr;
}
}
</script>

that'll work but you need to convert it to php ;)