Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the httponly property to false in a cookie

Tags:

php

laravel

How would i using Laravel make a cookie using Cookie::Make (Or something else) and set the httponly property to false?

I would want to do this as the cookie contains a key which my JS must be able to read.

like image 499
Sam Pettersson Avatar asked Dec 07 '22 03:12

Sam Pettersson


1 Answers

Laravel provides an option for this, but the docs don't show it. The best way is to look through the source. If you take a look at the CookieJar.php file here you'll see the httpOnly option.

public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true)

so simply do something like:

Cookie::make('MyCookie', 'MyValue', 60, null, null, false, false);
like image 116
Chris G Avatar answered Dec 17 '22 01:12

Chris G