Get PHP Session Value using AJAX/Jquery

Get PHP Session Value using AJAX/Jquery

Get PHP Session Value using AJAX/Jquery

In this Post We Will Explain About is Get PHP Session Value using AJAX/Jquery With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to get session value in jquery ajax Example

In this post we will show you Best way to implement Get variable from PHP file using JQuery/AJAX , hear for javascript variable value stored in php session with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

index.php

<?php
	session_start();
?>
<!DOCTYPE html>
<html>
<head>
	<title>How to Simple get PHP Session Value using jQuery</title>
css/bootstrap.min.css
3.1.0/jquery.min.js
3.3.7/js/bootstrap.min.js
</head>
<body>
<divclass="container">
	<h1 class="page-header text-center">How to get PHP Session Value in jQuery</h1>
	<div class="row">
		<div class="col-xl-6 col-xl-offset-3">
			<h3 class="text-center">Set simple jquery to php Session Value ( $_SESSION['value'] )</h3>
			<form method="POST" action="do_session.php">
				<input type="text" name="set_sessionVal" class="form-control" placeholder="enter simple value" required>
				<div style="margin-top:11px;">
				<button type="submit" class="live btn btn-success">Set Value</button> <a href="logout.php" type="button" class="live btn btn-danger">Remove session Value</a>
				</div>
			</form>
 
			<button type="button" id="checkSession" class="btn btn-success" style="margin-top:30px;">Check Session in jQuery</button>
		</div>
	</div>
 
	<input type="hidden" value="<?php
		if(isset($_SESSION['value'])){
			echo $_SESSION['value'];
		} 
	?>" id="session">
</div>
<script src="session.js"></script>
</body>
</html>

do_session.php

<?php
	session_start();
 
	$set_sessionVal=$_POST['set_sessionVal'];
	$_SESSION['value']=$set_sessionVal;
 
	header('location:index.php');
?>

logout.php

<?php
	session_start();
	unset($_SESSION['value']);
	header('location:index.php');
?>

session.js

$(document).ready(function(){
	//here simple conditions of check session
	$('#checkSession').click(function(){
		var session = $('#session').val();
		if(session == ''){
			alert('Live Session not Set');
			console.log('Live Session not Set');
		}
		else{
			alert('here simple Current Live Session Value: '+session);
			console.log(session);
		}
	});
});

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Get variable from PHP file using JQuery/AJAX And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   jQuery Save and retrieve Session Variable Value
  2.   Laravel create Dynamic Email Templates from Database
  3.   Laravel 6 JQuery Ajax Post Request Example
  4.   Laravel 5.6 Data Export to CSV and Excel Example
  5.   Include Header navigation and Footer in PHP
  6.   vue.js Dynamic Dependent Dropdown using PHP
  7.   Angularjs set focus on first textbox
  8.   PHP Laravel Store Array in Session Examples
  9.   PHP Webcam Capture Image Save from Camera using jQuery
  10.   AngularJS Add ng class to toggle Active Menu