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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing values between javascript and PHP using cookies

    hi

    I know there are issues with passing values obtained using javascript then wanting to use them in PHP, so heres where I'm having a problem.

    I have vars created in Javascript so have created a cookie containing them, loads new php page and want to load the cookie values back to php so I can write them to MYSQL after verifying more data from the user.

    Is this possible, Is this even a workable method, are there better ways to do this, can this even be achieved.

    I aam extremely new to this kind of thing so any assistance pointers or even full solutions would be appreciated.

    I am using Phorm (form tools) and get the initial javescript vars in my first form but dont want to use them until I have verified all the input from the user contained in aditional forms.

    Many thanks

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    yes you can use cookies , I would suggest sessions if only because they cater for users regardless of whether they have cookies enbaled or not (they are also simply easier to use)...

    in your form processing script ..
    PHP Code:
    <?php
    session_start
    () ;

    //validate your _POSTed variables etc
    //then add to the session
    $_SESSION['variable_name'] = $_POST['variable_name'] ;
    ?>
    then whenever you want to use them ..

    PHP Code:
    <?php
    session_start
    ();
    ?>
    <script>
    var variable_name = <?=$_SESSION['variable_name'] ;?>;
    /*etc*/
    </script>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Firepages

    Will see what i can do using sessions, will let you know how i get on


  •  

    Posting Permissions

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