Hooch Posted June 1, 2010 Share Posted June 1, 2010 Hey all.Is it possible to have a JS file carry my sessions?I have 1 important session that gets lost when I update something via JS.Thank you(I'm Googling for answers still) Link to comment Share on other sites More sharing options...
ballack999 Posted June 1, 2010 Share Posted June 1, 2010 javascript is client side, but php is server side.You can send session to javascript easily by using php tag and echo in javascript such as var session=<?php echo $_SESSION['xxx']; ?>; . Link to comment Share on other sites More sharing options...
Hooch Posted June 1, 2010 Author Share Posted June 1, 2010 Now how would I add the session to a link?Here is the code in the .js file window.location.href='page.php'; I would like to have something like window.location.href='page.php?t2=<?php echo $_SESSION['xxx']; ?>'; This returns the link exactly as you see it. It's not echo'ing the session.Thank you for your time. Link to comment Share on other sites More sharing options...
boen_robot Posted June 1, 2010 Share Posted June 1, 2010 $_SESSION['xxx'] will get a variable "xxx" that's part of the current PHP session... do you have such a variable?BTW, what you're trying to do is probably a bad idea... what exactly are you trying to do? There's perhaps a better way to deal with it altogether. Link to comment Share on other sites More sharing options...
Hooch Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks boen.I will try to explain my problem.I have paid someone to create a project for me that involves draggingimages in a set admin area. I then save the current positions of all theimages and then use this to display on the front end. Now comes the hard part.The current set up works great for retrieving from 1 table in the database.I want to make this more dynamic. Plus to make this even more difficultI have the option to add and subtract categories of images.What I have so far:The php part is pretty much done. I can select from any category created.I have 4 javascript files that are used in the static version. I want to make2 of these dynamic, so all my categories will use the same (4) .js files.I have the dynamic selection of categories in 2 sessions (on the php pages). $_SESSION['t2'] = $_GET['t2'];$_SESSION['t3'] = $_GET['t3']; These same sessions will be used to update tables from the .js files and also used to link back to theoriginating php page.This is where window.location.href='page.php?t2=<?php echo $_SESSION['xxx']; ?>'; Came from. So it actually should be window.location.href='page.php?t2=<?php echo $_SESSION['t2']; ?>&t3=<?php echo $_SESSION['t3']; ?>'; I hope it's a little more clear.Thank you Link to comment Share on other sites More sharing options...
justsomeguy Posted June 1, 2010 Share Posted June 1, 2010 If you name your .js files as .php then the PHP code will run. PHP code will not run in a .js file unless you configure the server to do that. Link to comment Share on other sites More sharing options...
Hooch Posted June 2, 2010 Author Share Posted June 2, 2010 What an easy (but not obvious) solution. Thanks Guy!Well..not obvious to me Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.