0

I have a download page that take arguments like the download URL, the download-counter data file url, and the page to return to after downloading. It is arranged like so:

start.php?url=...&page=...&file=...
(Download url, redirect page, counter file)

The problem is, when the redirect page contains PHP arguments with ? and & symbols, the URL becomes a confusing mess for PHP to work with.

Example:

start.php?url=URLTEXT&page=page?test1=x&test2=xx&file=FILETEXT

What should happen:

url=URLTEXT
page=page?test1=x&test2=xx
file=FILETEXT

what happens:

url=URLTEXT
page=page?test1=x
test2=xx
file=FILETEXT

How could I substitute characters or somehow make these arguments pass correctly in php?

Thanks for any help you can give.

4

2 回答 2

2

好吧,我不确定您的“混乱”网址是什么样的。但是“?”之后的字符串 称为查询字符串,您可以使用

urlencode($normalString); //will be encoded for use in URL
urldeocde($queryString); //will be decoded for "normal" use

编辑:

这是一些简短的示例:

echo "Encode for use in URL: ";
echo urlencode("this is a string & üäöllasdlk<bbb2");
echo "<br />";

echo "Decode to use it in your script: ";
echo urldecode($_SERVER['QUERY_STRING']);

输出:

用于 URL 的编码:this+is+a+string+%26+%C3%BC%C3%A4%C3%B6llasdlk%3Cbbb2 解码以在您的脚本中使用它:test=12

(假设您有一个包含变量的查询字符串test=12

于 2013-01-04T20:35:04.470 回答
-3

只需在您的 URL 字符串上使用 htmlspecialchars 函数:http: //php.net/manual/en/function.htmlspecialchars.php

于 2013-01-04T20:30:40.180 回答