Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

php - Dealing with long URLs

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).

So in my index.php:

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

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.

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:

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

long_url_test.php:

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. Write a form to the page with a squillion hidden fields with your data in it, then make the link POST the form.
  2. The same as #1, but with javascript.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...