douhuitan5863 2017-05-16 08:37
浏览 423
已采纳

如何在laravel中获得cookie值

I am setting cookie in in blade file using javascript by below piece of code

function showPosition(position) {
    var lat=position.coords.latitude;
    var lng=position.coords.longitude;
    document.cookie="lat=" + lat;
    document.cookie="lng=" + lng;
    //var allcookies = document.cookie;
    //alert(allcookies);
    localStorage.setItem('latLng',latLng);
}

and in model i try to get cookie

$lat = Cookie::get('lat');
$lng = Cookie::get('lng');
dd($lat);

but it shows me null. Any help please.

  • 写回答

2条回答 默认 最新

  • doujiaoben28596 2017-05-16 08:46
    关注

    Laravel stores cookies encrypted, so Cookie::get() will only retrieve cookies set by Laravel. You should use the native $_COOKIE['lat'] in PHP to retrieve cookies set for example in JavaScript.

    You can find out more here:

    https://laravel.com/docs/4.2/requests#cookies

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 笔记本上移动热点开关状态查询
  • ¥70 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52