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
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Use php session data in jquery

    Hello,

    I would like to setup my jquery dialoge window based on my stored session data:

    For instance, if my dialogue is opened, it should remain opened next time I visit my page again (meaning whenever my session data still exists)...

    I however run into issues all the time I try to find a working solution...

    Could u suggest me a working approach for this by any chance?


    (Codesnippet of the sessions-part
    Jquery part:
    Code:
    	$(".windows").dialog({
    	autoOpen: false,
    	stack: true,
    	draggable: true,
    	position: [600, 200],
    	height: 500,
    	width: 650,
    			open: function( event, ui ) {
    			$window = $(this).attr('id');
    			$.post("session.php", {"status":"open", "window":$window}, function(results) {
    			$('#logwindow').append(results);
    			});
    			},
    			close: function( event, ui ) {
    			$window = $(this).attr('id');
    			$.post("session.php", {"status":"closed", "window":$window}, function(results) {
    			$('#logwindow').append(results);
    			});
    			}
    	})
    session.php:
    Code:
    <?php
    session_start();
    
    $_SESSION[$_POST["window"]] = $_POST["status"];
    $parsetext = $_POST["window"] . ": " . $_SESSION[$_POST["window"]] . "<br/>";
    print $parsetext;
    ?>
    Thanks in advance!

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you would need to use cookies

    session is emptied when you close the browser
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    33
    Thanks
    18
    Thanked 0 Times in 0 Posts
    that's good enough for me session is fine

    I have the following issue:

    where/how do I call the dialog to be opened?

    this is my current idea:
    index.php:
    Code:
    <?php include("sessionsetup.php"); ?>
    sessionsetup.php:
    Code:
    <?php
    if(isset($_SESSION["window1"])) {
    $parsetext1 = $_SESSION["window1"];
    if ($parsetext1 === "open")
    {
    echo "<script type='text/javascript'>$('#dialogwindow1').dialog('open');</script>"; 
    }
    }
    ?>
    but this won't work =/

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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