is it possible to create session variables with jquery or javascript or do i have to use ajax to call a php that does that?
3 Answers
You'll need to use a server-request. Javascript operates only on the client, and session data is stored on the server.
// example of passing variable 'name' to server-script for session-data-storage
$.post("createSession.php", {"name":"jonathan"}, function(results) {
alert(results); // alerts 'Updated'
});
And on the server, something like:
session_start();
$_SESSION["name"] = $_POST["name"];
print "Updated"; // What will be passed to Javascript "alert" command.
4 Comments
ajsie
js can create cookies but not sessions?
Sampson
Cookies exist on the user computer, but sessions exist on the server hosting the website.
Sampson
That is why cookies are less-secure than session variables. Users have complete access to cookies (since they exist on the users computer). But session data is stored on the server, where access is restricted generally.
Md. Mahamudul Hasan Khan
I am new to web language. Can you tell me what it means
$.post("createSession.php", Is it possible to create session using jquery???You can just use php to create a session variable, no javascript required.
<?php
session_start();
$_SESSION['uniquely'] = microtime(true);
?>
I suppose if you wanted to create a session when a user hovered over an image, or clicked on a link, you could use jquery to make an ajax call to set the session.
Thoughts?
Comments
Try with this:
<td><?php echo get_tracking_code($borrower->id) ?></td>
<td><?php echo ucwords(strtolower("{$borrower->name} {$borrower->name_middle} {$borrower->name_last}")); ?></td>
<td><?php echo get_purpose($borrower->initial_loan_purpose); ?></td>
<td>Php <?php echo number_format($borrower->initial_loan_amount); ?></td>
<td><?php echo get_location($borrower->location); ?></td>
<td><?php echo $borrower->number_claimed_by_lenders; ?></td>