Forum Moderators: coopster

Message Too Old, No Replies

Changing a string - Then converting it back again

Which function to use?

         

Nick_W

11:19 am on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

If I have a 10 digit string and just want to temporarily mask it and then (using the masked value) get the original back, which is the best function/approach?

There are no security issues, I just need to change a string, pass it around the site a bit (in a url) and then change it back again...

Many thanks, hope that's not too confusing heh!

Nick

dmorison

11:29 am on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By digit, do you mean the string is a number containing only the characters 0..9; or do you mean 10 character?

coopster

11:43 am on Aug 20, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at the serialize function to see if that is what you can use...

dmorison

11:50 am on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This XOR function looks URL safe (i.e. no %XX conversion required) for all digits and letters (upper and lower case)
function obfuscate($input)
{
$output = "";

$j = strlen($input);

for($i=0;$i<$j;$i++)
{
$output .= chr(ord(substr($input,$i,1)) ^ 0x02);
}

return $output;
}

Just call it twice to return to the original string...

Nick_W

12:39 pm on Aug 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>do you mean 10 character?

Yes. Sorry, numbers and letters but nothing else....

I'll have a look at serialize and your function there dmorrison, thanks very much ;)

Nick