Connecting Tech Pros Worldwide Forums | Help | Site Map

can i assign value returned from javascript function to php session variable

Newbie
 
Join Date: Oct 2008
Posts: 26
#1: Mar 14 '09
i am stuck in the problem, where after user logs in successfuly, i take him to the login thanks page. now on that page i need to retain the login name. I am not sure how to this.

i have written a query string which passes the SID from this page.

<a href="loginthanks.php?<?php echo htmlspecialchars(SID); ?>" >

now how can i send the login name to next page.

Also i want to store this value of login name in some session variable, so that i can display this on everypage user navigates. my problem can also be resolved if i can assign the value returned from javascript function to the a session variable on next page, something like this:

this php code is written in loginthanks.php file
<?php
session_start();
$_SESSION['user_logged'] = true;
$_SESSION[loginName] = echo '<script type="text/javascript" getLoginName();';
?>
where this function returns the login name.
if this code is syntactically correct then i can this value of session variable?

please help!!

many thanks in advance.



Newbie
 
Join Date: Jul 2008
Posts: 13
#2: Mar 14 '09

re: can i assign value returned from javascript function to php session variable


Here are possible answers to your query (I suppose I did undertand your query properly)

1. How can I add login name to $_SESSION : First through your javascript function (which you should define in <head> tag ) use the code
function assignLoginName()
{

location.href = Add the login name as a query parameter either ? or & depending the other query parameters you pass. This should redirect you to the page that you display after login say succesfull_login.php

}

in php
if (isset($_GET['login_name']))
save it in session.
I hope this does solve your query.

I suppose this will also solve your second query, once you have the login_name in session you can pass it to just any page you want. Work it out and reply back

Regards,
Abhijit
Newbie
 
Join Date: Oct 2008
Posts: 26
#3: Mar 14 '09

re: can i assign value returned from javascript function to php session variable


i am not sure about how suggested code would work. i have already called a function on click of submit button, after user enters user id & password.
now how would i call another function on its click.

i am pasting the complete code here.

<a href="loginthanks.php?<?php echo htmlspecialchars(SID);?>" > <input type="button" name="txt3" id="verifyLogin" value="log in" onclick = "return loginVerification()" /></a>

in loginthanks.php i have added the code:

<?php
session_start();
$_SESSION['user_logged'] = true;
$_SESSION[loginName] = echo '<script type="text/javascript" getLoginName();';
?>

where getLoginName(), returns the loginname entered by user.
Reply