views:

277

answers:

1

My problem: I have few buttons in the page I'm modifying - they have onclick events:

javascript:window.location.href='http://www.another.page.com/'; return false;

I have to send $_SESSION variable to redirected page. I can't do it in previous page because the variable will be different for each button. How can I do it?

+1  A: 

You can't set a session variable based on what button a user clicks, because Session data is stored on the server, not on the cookie.

What you can do is give each button a different GET variable, and then push that into the Session array when your page loads.

Original Page

    <a onclick="javascript:window.location.href='http://www.another.page.com/?button=1'; return false;">

    <a onclick="javascript:window.location.href='http://www.another.page.com/?button=2'; return false;">

    <a onclick="javascript:window.location.href='http://www.another.page.com/?button=3'; return false;">

Other Page

<?php
    if(isset($_GET['button']))
    {
        $_SESSION['button'] = $_GET['button'];
    }
    //..........process stuff.................
?>

Make sure to sanitize the GET value though.

Chacha102