• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How can I get user id from session in javascript?

javascriptphpcodeigniter


PHP Snippet 1:

<input id="userId" value="<?php $_SESSION['user_id'] ?>" style="display:none">

PHP Snippet 2:

$( document ).ready(function() {
   alert( $('#userId').val() );
   console.log('done');
});

Related Snippets

What is PHP's equivalent of JavaScript's "array.every()"?

Laravel 8 factory state afterCreating

Respond with status code 401 on authentication failure using Laravel and Passport?

With doctrine ODM, can I embed many subdocuments in a main document?

how to make my own auto increment in php?

Toggle between a textbox and a select using PHP

Laravel 5 issue with wherePivot

Laravel views are showing from cache on one server but works fine on other server

how to validate form data in codeigniter 4

Override default Auth routes in Laravel 7

how to insert data into select2 search input after scan using qrcode

protect my blog content

Get Header Authorization value of a login api (sent with username and password in json body) using php curl

php echo xml documents with header

Detect if PHP session exists

About Contact Privacy policy Terms and conditions