-1

EDIT: I solved my problem in total differnt way, thanks to those who respond anyways! helped a lot! I need to send a table on HTML through a get variable.

The code is:

<html>
<head>
<meta charset="utf-8" />
<title>Itinerario</title>
<link rel="stylesheet" type="text/css" href="itine.css"/>
</head>
<body bgcolor="#FFC334" link="black" vlink="black" alink="white">
<?php

$html='
<font face="arial">
<center>
<table bgcolor="#F3F3F3" style="border:2px solid black;" cellpadding="10" cellspacing="10">
 <tr>
  <td></td>
  <td>CELL 1</td>
  <td>CELL 2</td>
 </tr>             
</table> 
</center>
</font>
';

echo $html;

echo '<a href="archive.php?itine='.$html.'">LINK ME</a>';

?>
</body>
</html>

The other part its just a $_get:

<?php
 $variable = $_GET['itine'];
?>

If I replace the $html in the URL for text it works fine but adding table structure sends nothing (no error), only blank. Any ideas?

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
  • 3
    You need to URLencode the html: `urlencode()` but why would you want to do this? This sounds like there might be a better way for it – Pekka Oct 24 '13 at 13:26
  • Do you *really* need to send it through `$_GET`? Can't you just send `CELL1;CELL2` through `$_GET`? [Keep in mind that `$_GET` can't be that large](http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request). – h2ooooooo Oct 24 '13 at 13:26
  • Agreed with @Pekka웃 -- Why send the whole table? – tymeJV Oct 24 '13 at 13:26
  • this is an unsual way of doing this and isnt recommended BUT you could possibly do it by using: htmlentities(); then convert it back on the second page – NoLiver92 Oct 24 '13 at 13:27

4 Answers4

2

You wouldn't be able to send such complex HTML via GET, especially unescaped.

If you must pass HTML from page to page, you could base64_encode() the HTML, and probably gzcompress() it too. This would help prevent hitting the character limit for GET requests, but wouldn't eliminate the problem for very large tables.

I did once have to do something similar, which required passing a lot of data into GET variables. I had to create a couple of functions to make them GET friendly though:

function shrink($str) {
    $str=strtr(base64_encode(addslashes(gzcompress($str,9))), '+/=', '-_,');
    return $str;
}
function unshrink($str) {
    $str = gzuncompress(stripslashes(base64_decode(strtr($str, '-_,', '+/='))));
    return $str;
}

The shrink() function there gzips the string at compression level 9, and removes any characters from the encoded output that could cause issues for GET requests.

unshrink() does the opposite.

If you were to include those functions, you could do something like this in your example:

$html='
<font face="arial">
<center>
<table bgcolor="#F3F3F3" style="border:2px solid black;" cellpadding="10" cellspacing="10">
 <tr>
  <td></td>
  <td>CELL 1</td>
  <td>CELL 2</td>
 </tr>             
</table> 
</center>
</font>
';

echo $html;

echo '<a href="archive.php?itine='.shrink($html).'">LINK ME</a>';

Then to de-compress at the other end:

echo unshrink($_GET['itine']);

This was my first actual post here, so I hope it offers some help!

1

urlencode(), and no need to decode them, because when they are assigned to $_GET or $_POST they should already have been decoded.

Horse SMith
  • 1,003
  • 2
  • 12
  • 25
  • Indeed no need to decode. Thanks. Ill have to find another solution to my problem because the string its very long and GET wont support it. – Enric Grau-Luque Oct 24 '13 at 13:56
  • 1
    Yeah, but why are you doing it? You can do input arrays in a form. If this is some kind of crawling or loading of some website, you could use cURL then DOMDocument to get it all organized. If you really want to send it all like that, you could do it a little bit at a time, if any gui is needed maybe write some JavaScript. Lots of solutions for this, but yeah, kinda want to know why you want to do this so it's easier to help you. – Horse SMith Oct 24 '13 at 14:27
0

The first problem is that you have a double quote in the HTML you want to send, this closes off the double quote of your a href.

Secondly, you might bump in the limitation of GET requests, theoretically they can only be 256 characters long.

Lastly, I would propose to you to urlencode/decode the data you try to send trough the url:

Encode:

echo '<a href="archive.php?itine='.urlencode($html).'">LINK ME</a>';

Decode:

<?php
    $variable = urldecode($_GET['itine']);
?>
Jeroen
  • 982
  • 1
  • 6
  • 14
  • Here it states that the limit its a myth: http://www.w3.org/2001/tag/doc/get7#myths But yeah, my string its long though and it doesnt pass through get so i will have to find another way! Thanks! – Enric Grau-Luque Oct 24 '13 at 13:54
0

Well since you have some limitations about string length on $_GET, it's preferable not to do this. If you explain better what you need, maybe we can provide you another solution.

Tiago Oliveira
  • 57
  • 1
  • 1
  • 3
  • As matter of fact GET won support my original string so ill look for other solution. BTW just looked that up and here it states that the limit istelf its a myth: http://www.w3.org/2001/tag/doc/get7#myths – Enric Grau-Luque Oct 24 '13 at 13:58
  • I don't know which is the limit itself, but one thing I can say, it exists. And it's easy to test, just send a GET with lots of text and you will se it cutted. – Tiago Oliveira Jan 09 '14 at 16:10