Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    US Florida
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts

    getting a session id inside javaScript

    Hello everyone,

    I have session_start() at the begining of my home page. In my home page I'm calling a fileName.js inside my <head></head> tags. My guestion is...

    How do I get the session id inside fileName.js? Or is there a way to pass it to fileName.js from the home page(index.html)?

    Thank You in advance.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Ummm...what kind of server side coding are you using???

    Is that PHP? session_start()???

    I'm unaware of any way to *have* session id's if you are using only HTML.

    So your home page would presumably be a PHP page, no?

    Or you could use PHP to build the ".js" file, of course.

  • Users who have thanked Old Pedant for this post:

    agfre44_9873 (09-05-2009)

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You may also create a javascript global variable, that means there is no need to include that variable inside the fileName.js file
    PHP Code:
    <script type="text/javascript">
    var sessionID='<?php if(isset($_SESSION['PHPSESSID'])){echo $_SESSION['PHPSESSID'];} ?>';
    </script>
    <script type="text/javascript" src="fileName.js"></script>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    agfre44_9873 (09-05-2009)

  • #4
    New Coder
    Join Date
    Apr 2009
    Location
    US Florida
    Posts
    25
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ThanK you Old Pedant and Kor. You are both helpful!

    My session_start() is in my home page index.php. I figure out how to do it (simple. I was making a big deal out of it)

    <head>
    <script>
    funtion process(valueA, valueB) { ... bla bla bla ...}
    </script>
    </head>

    <body onload="process('<?php echo session_id() ?>' , '<?php echo GetHostByName(#REMOTE_ADDR) ?>' )">

    bla bla bla...

    </body>

    I know the way I game about it is a little longer. Kor has the part I was looking every where on the net, the session id part. How do I get the ip address?

    What I'm trying to do is to build a button that passes an increment. If the client don't have a session id and an IP addrs, they can't use the button. I want to use the id, ip, and another id to verify is the client via server and client communication. This might sound silly but It makes sense to me. Feel free to attack my logic.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •