dweb Posted May 5, 2012 Share Posted May 5, 2012 Hello Wonder if you can help; I have an issue with sessions, I have stripped out a ton of code to give a more simple example below; Basically when I click the "Button 1" link, it should just display "Clicked button 1" and when I click the "Button 2" link, it should just display "Clicked button 2" But for some reason it's displaying "Clicked button 1" and "Clicked button 2" no matter what Any idea why? Thank you <?php session_start(); if(isset($_GET['1'])) { $_SESSION['result'] = 1; } if(isset($_GET['2'])) { $_SESSION['result'] = 2; } ?> <?php if(isset($_SESSION['result']) == 1) { echo "Clicked button 1<br>"; } ?> <a href="?1">Button 1</a> <br /> <br /> <?php if(isset($_SESSION['result']) == 2) { echo "Clicked button 2<br>"; } ?> <a href="?2">Button 2</a> <?php unset($_SESSION['result']); ?> Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 5, 2012 Share Posted May 5, 2012 if(isset($_SESSION['result']) == 1) isset returns true or false indicating if the variable is set. Since it is set (in the code above that), it is returning true. When you compare true to any integer (1 or 2) the IF is returning true. So, both IF statements, as written, are true. if ( (isset($_SESSION['result'])) and ($_SESSION['result'] == 1) ) should produce the results you are expecting. Quote Link to comment Share on other sites More sharing options...
dweb Posted May 5, 2012 Author Share Posted May 5, 2012 Thank you, worked great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.