0

I am dealing with some data from my dataBase, on my PHP(html) page.
So before the Html code starts I put some PHP code, and I want to "live" (edit note: probably "leave" or "give") my html page some text data, so the js will deal with it.
I've created it like that:

<?php
/*some code.. */
setcookie("name","**BIG DATA**");
?>
<html>
<!--All the HTML code-->
</html>

Because the data in the cookie is big, it sends me the "Bad Request" error page, and it blocks all my site. So I needed to delete all my cookies in my browser so it will continue to work.
I've tried to divide it to an array of cookies, so each cookie will be about 300 chars, but it doesn't help...

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
Yehonathan Jacob
  • 43
  • 1
  • 1
  • 5

2 Answers2

0

The 4K limit you read about is for the entire cookie, including name, value, expiry date etc. If you want to support most browsers, I suggest keeping the name under 4000 bytes, and the overall cookie size under 4093 bytes

Wordica
  • 2,427
  • 3
  • 31
  • 51
  • 4
    Copy + Paste !== Answer – Jonas Wilms Jul 19 '17 at 20:24
  • 2
    if you think its a duplicate, flag it as duplicate. That will help the OP more, as the answers in the original thread are better... – Jonas Wilms Jul 19 '17 at 20:29
  • I do not se whole code, I don't know its duplicated or not ... maybe problem is with to big cookies, maybe not ... I don't understand peoples with XXX score in here ... You always have some problems but do not try to help ... I give You +1 score ;) – Wordica Jul 19 '17 at 20:34
0

Simply output into js directly e.g:

<script>

var fromserver="<?php
/*some code.. */
echo "**BIG DATA**";
?>";

And you may store it in localStorage if you want to:

if(fromServer){
 //store
localStorage.fromServer=fromServer;
}else{
 fromServer=localStorage.fromServer;
}

alert(fromServer);

It will behave like a never expiring cookie, but the memory limit is much higher.

</script>
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
  • the problem width outpot to the js directly, is that forstly it can make promlem if in the data I have ",' and some other text promlem (for eampel enter in the tex), secondly, it is un tidy code... you can't just put text in the HTML.. – Yehonathan Jacob Jul 19 '17 at 21:03
  • @user5460170 yes you could. Depends on the usecase. – Jonas Wilms Jul 20 '17 at 08:07