tags:

views:

90

answers:

6
+1  Q: 

get values in url

I need to get values in the url as it is

ex:

http://www.example.com/index?url=1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA==

but vriable url give me value of "1 LY2ePh1pjX4tjZ4 GS393Y2pjd16Cbq63T3tbfzMzd16CarA=="

Even though i have expected "1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA=="

any one can help me for this or know the reason

A: 

The client sending the request apparently isn't URL encoding the value correctly. You can re-encode it after it's being decoded like this:

urlencode($_GET["url"])
icktoofay
+2  A: 

You see, you need to encode certain characters if you need to send them in a URL. For further references, I suggest you should read this Page. It seems that the URL you are getting isn't being encoded properly. If the URL is coming from your site, then I would suggest you to encode it properly.

In PHP, there is a function called urlencode, which may help you with this task.

A short explanation

URLs can only be sent over internet using ASCII character set.If you want to send characters which is outside this set, you need to encode it.URL encoding replaces unsafe ASCII characters with % followed by two hexadecimal digits corresponding to the character values in the ISO-8859-1 character-set.

Night Shade
It’s rather UTF-8 that is used these days.
Gumbo
A: 

IT convert %2B to space

scit
If you have a comment, make a comment. This is not the answer it claims to be.
David Dorward
Reputation 1 can't make comment I think. I don't think he deserves to be demoted for this.
Rosdi
I'm pretty sure they can make comments on answers to their own questions.
David Dorward
Peter Ajtai
A: 

The parameter you sent is wrong, it should have been encoded like so..

<?php
    echo '<a href="http://www.example.com/index?url=', urlencode('1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA=='), '">';
?>
Rosdi
A: 

i have added encoding correctly now,It convert == correctly, but + sign encode to %2B correctly but in decode process it convert to space

scit
A: 

As it seems that you’re having a Base-64 value there: You can use the URL safe alphabet for Base-64 that uses - and _ instead of + and / respectively:

$base64 = "1+LY2ePh1pjX4tjZ4+GS393Y2pjd16Cbq63T3tbfzMzd16CarA==";
// plain Base-64 to URL safe Base-64
$base64_safe = strtr($base64, '+/', '-_');
// URL safe Base-64 to plain Base-64
$base64 = strtr($base64_safe, '-_', '+/');

And if you know the length of the data, you can also omit the = padding:

rtrim($base64, '=')
Gumbo