I have saved some value in cookie using jQuery, but I want to get cookie value using PHP. How can I access jQuery cookie value using PHP. I am following these code.
My JavaScript code:
<script type="text/javascript"> function vendorDetails(id){ $.cookie('user_id',id); alert($.cookie('user_id')); window.location.href="<?php echo base_url('index.php');?>"; } </script>
My PHP code :
<?php echo $_COOKIE["user_id"]; die; ?>
Here you need to set the path. Follow the example code.
First off all you need to put jquery.cookie.min.js link. If you do that then it is good of copy the below jquery.cookie.min.js link and paste in your code.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
Now follow this code for store value in cookie using jquery:
<script type="text/javascript"> function vendorDetails(id){ $.cookie('user_id', id, { expires: 7, path: '/' }); window.location.href="<?php echo base_url('index.php');?>"; } </script>
Access jquery cookie value using php:
<?php echo $_COOKIE["user_id"]; exit(); ?>
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io