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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahullko05
    New Member
    • Oct 2008
    • 34

    #1

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

    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="loginthan ks.php?<?php echo htmlspecialchar s(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.
  • abhighat4214
    New Member
    • Jul 2008
    • 13

    #2
    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_logi n.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

    Comment

    • rahullko05
      New Member
      • Oct 2008
      • 34

      #3
      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="loginthan ks.php?<?php echo htmlspecialchar s(SID);?>" > <input type="button" name="txt3" id="verifyLogin " value="log in" onclick = "return loginVerificati on()" /></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.

      Comment

      Working...