How to URLENCODE url with variables? - php

I need to URLENCODE this:
<?php echo 'chart.php?api_url=http://0.chart.apis.google.com/chart?'.$chart1title.$chart1type.$chart1size.$chart1barsize.$chart1gridlines.$chart1data.$chart1color.$chart1bgcolor.$chart1visibleaxis.$chart1axislabels.$chart1axisdatascale.$chart1axisranges.'alt="answeredcalls"';?>
And then decode it on the other side. How can I do this???

'chart.php?api_url=' . urlencode('http://0.chart.apis.google.com/chart?'.$chart1title.$chart1type.$chart1size.$chart1barsize.$chart1gridlines.$chart1data.$chart1color.$chart1bgcolor.$chart1visibleaxis.$chart1axislabels.$chart1axisdatascale.$chart1axisranges.'alt="answeredcalls"');

Generally you won't have to use urldecode() when accessing $_GET parameters in PHP. It will be, essentially, decoded for you.
The previous answer is a good solution to the encoding part of the question.

Related

How to use GET method in php for url which has %20?

I tried to use GET method in php, but the url has home%20phone as query parameter
When i tried to read it using
<?php echo $_GET['home%20phone']; ?>
it is not working..So, how to read variables like this.
thanks.
%20 is a URL-encoded space character. Try this:
<?php echo $_GET['home phone']; ?>
If you're not sure what the keys in your array are, you can always use print_r($_GET) or var_dump($_GET) to see what's in there.
Do a var_dump($_GET) to see the keys the variables are mapped to.
Use urldecode() for extracting exact value from the get method.
Refer: http://php.net/manual/en/function.urldecode.php
<?php echo urldecode($_GET['home%20phone']); ?>

Is it possible to base64 encode the file at a URI?

I've just been fiddling around with PHP, and I want to know if it's possible to do such a thing.
If so, can you please provide example code?
Update: What I mean, is I want to encode whatever file may be at the URI, not the URI itself. Sorry if I'm not clear.
You can put:
base64_encode(file_get_contents('http://www.google.com'));
I don't see why not...
<?php $file = file_get_contents("http://example.com/myfile.txt");
$encoded = base64_encode($file);
file_get_contents function will grab the HTML of given URL and base64_encode function will encode it.
<?php
$content = file_get_contents("http://google.com");
$encodedContent = base64_encode($content);
?>
You want to base64-encode a URL? Simple...
base64_encode($uri)

what is correct and secure vay to pass url through url

I want to pass url (or even several urls) through url, i.e. use url like http://domain/file.php?url1=...&url2=.... The question is how to make such urls safe and working. Will urlencode() help.
BTW, if I do urlencode($url), do I need to urldecode() before doing header("Location: $url")
Thank you in advance!
My proposal is to use:
http://php.net/manual/en/function.http-build-query.php
Will urlencode() help.
yes.
BTW, if I do urlencode($url), do I need to urldecode() before doing
header("Location: $url")
no. you'd need to encode the single urls which go to the final url, i.e.
$url1= "http://www.example.com";
$final = "http://yourdomain.com?url1=".urlencode($url1);

convert this to japanese character (encoding)

Please help me convert this... I dont know how to call this kind of data, is it hex?
2%E6%9C%8819%E6%97%A5
I believe that this should be printed as 2月19日
How can I convert 2%E6%9C%8819%E6%97%A5 to be 2月19日 using PHP?
Thank You
That looks like it's URL encoded http://en.wikipedia.org/wiki/Url_encoding
PHP UrlDecode might do the trick.
http://www.php.net/manual/en/function.urldecode.php
There's an example at that link which shows url decoding the querystring of a page. I don't know PHP, but you might want soemthing like the following:
<?php
$original = "2%E6%9C%8819%E6%97%A5";
$decoded = urldecode($original);
echo $decoded;
?>

php redirect and querystring

i have script
<?php
$to = $_GET["to"];
header("Location: $to");
?>
if i call script such
out.php?to=http://site.ru/page.php?param1=1&param2=2
in param $to be only http://site.ru/page.php?param1=1&
how to fix? i want that $to = http://site.ru/page.php?param1=1&param2=2
You can escape the URL at the site calling out.php:
Go to $to
& is a reserved character in an URI. When you access this URL, &param2=2
is interpreted as belonging to the current URL and not to the value of to.
If you want to transmit it literally, you have to encode it with %26:
http://site.ru/page.php?param1=1%26param2=2
Most programming languages provide a function to do so. (e.g. JavaScript, PHP). The best thing is to encode the whole URL.
$to must be urlencoded, but note that you giving a redirect script to anyone, so, any phisher can use it.
So, it would be better to store urls in the database and pass only an identifier.
try encoding the to URL in base64 and then in the example that u have shown decode it before you pass it to the header :)
urlencode it
urlencode($to)
I ran into the same problem before, this is what I did:
$arr=explode('?to=',$_SERVER['REQUEST_URI'],2);
$new_to=$arr[1];
Now you can use the $new_to variable.
Of course if you're using this for production environment, I would recommend encoding the url as the other answers advised. I was using it for testing curl script. getting the variable this way has lots of flaws, so be careful.
You can use a Function called "html_entity_decode"
Click Here for more information about this function
or use md5 function to encrypt the URL and then decrypt it when you put it into a varriable.
I hope this can help you

Categories