#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13

    Exclamation Include PHPSeesion in Javascript?


    Hello guys me again, is there a way to include the $PHPSESSID
    in a javascript array?

    example

    Code:
    //Configure Link array
    arMenu1 = new Array		//Main Site
    (
    "124","102","1",		//left, top
            "http://www.fastburst.com","<b>Main Site</b><br>",
    		"http://www.fastburst.com/news.php","All News",
    		"http://www.fastburst.com/archive.php","News Archives",
    		"http://www.fastburst.com/spotlight.php","Site Spotlight",
    		"http://www.fastburst.com/stats/","Site Statistics",
    		"http://www.fastburst.com/events.php","Upcoming Events",
    		"http://forums.fastburst.com","FastBurst Forums",
    		"","<hr width=100% size=1 color=#ffffff>",
    		"","<b>Company Info</b>",
    		"http://www.fastburst.com/view.php?id=6","About Us",
    		"http://www.fastburst.com/view.php?id=9","A Look Ahead",
    		"http://www.fastburst.com/view.php?id=7","Goals & Sites",
    		"http://www.fastburst.com/view.php?id=8","History",
    		"http://www.fastburst.com/view.php?id=10","Overview",
    		"http://www.fastburst.com/view.php?id=5","Contact Us",
    		"http://www.fastburst.com/staff.php","The Staff",
    		"","<hr width=100% size=1 color=#ffffff>",
    		"","<b>Employee Login</b>",
    		"http://www.fastburst.com/employee/","Login Here",
    		"","<hr width=100% size=1 color=#ffffff>",
    		"http://www.fastburst.com/view.php?id=","Jobs Available",
    		"http://www.fastburst.com/view.php?id=","Application"
    )
    I want to add the session id to the links:
    "http://www.fastburst.com/view.php?id=5&$PHPSESSID","Contact Us",


    But I cant get it to work. is it possible at all?

    I was using this php code to make my own little phpsession
    PHP Code:
    $session=md5(uniqid(microtime())); 
    But dont know if I can use it with javascript.

    Thanks
    - James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    you can just echo into your javascript array as you would anywhere else..

    <html....
    <script>
    alert("<?=$PHPSESSID;?>");
    </script>
    .../html>
    resistance is no longer futile :: 423
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13
    If I am not mistaken wouldnt that just bring up a alert window?

    I want the session to be included with the link but the link is generated by a java array.

    is it possible?

    - James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    yes it will just bring up a javascript alert - its only a sample... by the same means you can echo a javascript variable

    E.G.
    <script>
    var phpsessid=<?=$PHPSESSID;?>


    and doc.write that where you wish ...or directly into your javascript array

    arMenu1 = new Array //Main Site
    (
    "124","102","1", //left, top
    "http://www.fastburst.com","<b>Main Site</b><br>",
    "http://www.fastburst.com/news.php?<?=$PHPSESSID;?>","All News",
    "http://www.fastburst.com/archive.php","News Archives",
    "http://www.fastburst.com/spotlight.php","Site Spotlight",
    "http://www.fastburst.com/stats/","Site Statistics",
    .......
    resistance is no longer futile :: 423
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13
    Nope no luck niether worked.
    the var caused a error in the script

    and the direct just printed out the "<?=$PHPSESSID;?>" in the link itself.


    ok what about this

    is there a way in java to print out some kind random number our date after the link to look like a session?

    $session=md5(uniqid(microtime()));

    this is what I am using for my sessions now, thru php

    - James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  10. #6
  11. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    if <?=$PHPSESSID;?> or <?php echo $PHPSESSID;?> get printed to screen then that page is not being parsed at all ? is it a .HTML page? if so you gonna have to change it to .php (or .htm if you are set up for that)
    resistance is no longer futile :: 423
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13
    Nope itis in a php page, teh scripting is in the

    submenu.js file

    http://www.fastburst.com

    use the side links and you can see what I mean. the side menus is a java script display you are welcome to save the page so you can see the .js scripts

    the function for the submenus.js in engine.js

    but all driven by javascripting. but all included in php.


    - James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13
    WARNING! THE LINK IN THE ABOVE POST POPS OPEN A NUMBER OF ADVERT WINDOWS AND REQUESTS YOU DOWNLOAD SOFTWARE!

    It's always polite, when requesting assistance and providing a url, to inform those who may help that the link supplied will pop up windows all over their desktop.

    You will have to change the <script src="submenu.js"> to be
    PHP Code:
    <?
      
    include ('submenu.php');
    ?>
    Obviously you will need to change the javascript's file extension to .php (as firepages mentioned above). Then in the submenu.php file you will be able to use <?= $PHPSESSID ?> and have it parsed by the server.
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13
    ok question?

    if I did what you jsut said, would I not have to convert the whole javascript to php?

    Since it is written in Java.




    James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13
    No. You just leave it as it is and embed the php code as and when you need it. Just like you do if you place javascript on you main php page. You don't convert everything to php there do you? You have to give it the .php extension otherwise the server won't know there is any php in the page to parse before outputting the HTML and javascript to the visitor's browser. Why don't you try it.

    Btw, Java and and Javascript are two different things
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Edwards AFB, CA - USA
    Posts
    125
    Rep Power
    13
    Ok I did what you said and got a very nasty errors everywhere,
    and it totally distorted teh layout. any ideas?


    - James
    Need Web hosting? Prices as low as $5 a month!
    http://www.phoenix-hostin.com
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13
    "really nasty errors everywhere" and "distorted the layout" really doesn't help me to help you. What errors? Post the URL for the layout so I can see it. What about attaching the sidemenu.php file to your next post?
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...

IMN logo majestic logo threadwatch logo seochat tools logo