是否可以将 javascript 中的文本缩短为 php get 请求?

发布于 2024-09-30 08:20:48 字数 651 浏览 7 评论 0原文

我有一个非常具体的情况,其中一个 javascript 页面创建一个新窗口,其中包含元刷新,该窗口转到一个 php 页面,该页面有 1 个变量,其中包含 javascript 页面放入的所有内容。就像这样:

form.write('');

php页面的获取方式如下:

$data=$_GET['data'];
$order=htmlentities(stripslashes(strip_tags($order)));

问题是现有的应用程序有这个问题,我无法正确解决它,所以我想知道是否有某种方式对数据变量进行加密/编码,使其变得更短。 (我的apache服务器不喜欢82512个字符长的url...)就像tinyurl一样,但PHP必须能够将其解码回来。我不知道它的正确术语,所以我的谷歌搜索没有给我很多结果。

I have a very specific situation where a javascript page creates a new window with a meta-refresh in it which goes to a php page which has 1 variable with everything that the javascript page has put in it. Like so:

form.write('<meta http-equiv="refresh" content="0;URL=contentreq/index.php?data=');
Very long text with a lot of data (over 3000 characters)
form.write('" />');

The php page gets it like this:

$data=$_GET['data'];
$order=htmlentities(stripslashes(strip_tags($order)));

The problem is an existing app has this problem and I'm not in the situation to solve it properly so I was wondering if there is some way to encrypt/encode the data variable so that it will be a lot shorter. (My apache server does not like an 82512 characters long url...) Like tinyurl does, but PHP must be able to decode it back. I don't know the right term for it so my googling does not give me a lot of results.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤蝉 2024-10-07 08:20:48

正确的术语是压缩,但在这种情况下它也不起作用 - 一般 URL 长度限制为 2000 个字符,因为 IE 将其设置得那么低,并且如果您的数据难以压缩,您无法将 3kb 可靠地放入 2kb 中。

如果您无法将数据存储在 PHP 会话中,您想到的唯一想法是使用 Ajax POST 请求“提前发送数据”。它可以携带超过 3 kb 的数据。发送请求后,重定向到下一页,并让 PHP 从会话或其他内容中获取传输的数据。

这并不漂亮,但对于这个非常具体的场景,我想到的唯一想法。

另一个想法是,虽然这纯粹是客户端的,因此您无法传递 URL,但它是将数据存储在浏览器端 本地存储。

参考:

The right term for this would be compression, but it won't work in this case either - the general URL length limit is 2000 characters because IE sets it that low, and if your data is tough to compress, you won't fit 3kb reliably into 2kb.

The only idea that comes to mind, if you can't store the data in a PHP session, is to "send the data ahead" using a Ajax POST request. That can carry much more than 3 kb. When the request has been sent, redirect to the next page, and have PHP fetch the transmitted data from the session or something.

It's not pretty, but the only idea that comes to my mind for this very specific scenario.

Another idea, although this is purely client-side so you can't pass on the URL, is storing the data in the browser-side local storage.

Reference:

请叫√我孤独 2024-10-07 08:20:48

URL 缩短服务保存哈希 URL 对,并从短 URL 重定向到长 URL。这不适用于您的情况,因为您的数据 URL 部分是动态的。

您可以采取的方法是将所有数据放入 cookie 中,并让 PHP 脚本从该 cookie 中读取数据。另一种选择是将您的请求发布到 PHP 脚本,但这可能不适用。

另请注意,加密、编码和压缩之间存在差异。您不是要求加密或编码,而是要求压缩。

问候,
阿林

A URL shortening service saves hash-URL pairs and does redirects from the short URL to the long ones. This is not applicable to your case because your data URL part is dynamic.

An approach you can take is to put all your data in a cookie and let the PHP script read it from that cookie. Another option would be to POST you request to the PHP script, but this one may not be applicable.

Also note that there are differences between encryption, encoding and compression. You weren't asking for encryption or encoding, but compression.

Regards,
Alin

萌面超妹 2024-10-07 08:20:48

压缩是我正在寻找的术语。我已经重建了 javascript 函数,以使用 Pekka 发送的链接发布帖子。现在,这个东西可以处理奇怪的长查询。

谢谢!

这是我使用过的代码:

document.body.innerHTML += '

';

document.getElementById("dynForm").submit();

Compression was the term I was looking for. I've rebuilt the javascript function to do a post with the link Pekka sent. The thing now works with the bizzare long queries.

Thanks!

This is the code I've used:

document.body.innerHTML += '<form id="dynForm" action="http://example.com/" method="post"><input type="hidden" name="q" value="a"></form>';
document.getElementById("dynForm").submit();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文