处理长URL [英] Dealing with long URLs

查看:153
本文介绍了处理长URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 php 脚本生成链接,其中 URL 非常长(对于IE来说太长了) 处理 infact),例如 www.somesite.co.uk/here / query?foo = bar& bar = foo& ..... 其中 somesite.co.uk 获取(我无法更改为 post )。

I have a php script the generates links where-by the URL is very long (too long for IE to handle infact) such as www.somesite.co.uk/here/query?foo=bar&bar=foo&..... where somesite.co.uk gets the values (which I can't change to post).

所以在我的 index.php

echo "<a href='$url'>".$link."</a>";

对于 $ url 的值,一切正常在页面被视为预期的情况下,如果超出限制,页面上的数据将被截断。

All works fine for values of $url that are under the limit the page is seen as expected however if over the limit the data on the page is truncated.

我创建了这个 long_url_test.php 脚本,并按照预期为<$ c $的长值加载页面c> $ url

I created this long_url_test.php script and it's loads the page as expected for long values of $url

<?php
header('Location: $url');
?>

我需要帮助把所有这些放在一起,例如:

I need help putting this all together, something like:

index.php:

index.php:

echo "<a href='long_url_test.php'>".$link."</a>"; # and POST $url to script

long_url_test.php:

long_url_test.php:

<?php
$url=$_POST['url']
header('Location: $url');
?>

index.php 上显示的链接发布 long_url_test.php 的网址,它获取实际所需的网页,或者确实存在更好/更容易方式我应该这样做?

Where the link displayed on index.php posts the url to long_url_test.php which fetches the actual required page, or indeed is there a better/easier way I should do this?

推荐答案

为什么要生成如此荒谬的长URL?在这一点上,你显然错过了更好的解决方案,比如会话。

Why are you generating such ridiculously long URLs? At this point you're clearly missing out on a better solution like sessions.

如果我们只想在解决方案上打一个绑定:

If we just want to slap a bandaid on the solution:


  1. 将一个表格写入页面,其中包含数十亿个隐藏字段,其中包含您的数据,然后将表格链接POST。

  2. 与#1相同,但使用javascript。

稍微好一些:获取您要传递的任何数据并通过<$运行它c $ c> base64_encode(serialize($ your_data))并查看是否可以将其嵌入到URL中而不会遇到长度限制。如果您安装/启用Zlib,您也可以在其中抛出 gzcompress()

Slightly better: Take whatever data you want to pass and run it through base64_encode(serialize($your_data)) and see if you can embed that in the URL without running into the length limit. If you have Zlib installed/enabled you can throw a gzcompress() in there too.

仍然,我有非常很难想象没有更简单/更好的解决方案,您的数据保持服务器端。

Still, I have a very hard time imagining that there is not a far simpler/better solution where your data stays server-side.

这篇关于处理长URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆