2

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 3

8

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.
Sign up to request clarification or add additional context in comments.

4 Comments

js can create cookies but not sessions?
Cookies exist on the user computer, but sessions exist on the server hosting the website.
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.
I am new to web language. Can you tell me what it means $.post("createSession.php", Is it possible to create session using jquery???
1

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

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.