PHP_CHILD Posted January 13, 2013 Share Posted January 13, 2013 i want to use unique session values, set according to if condition. To use in same page. Like this <?php session_start(); ?> <form action="nn.php" method="post"> Username: <input type="text" name="lname" /><br><br> Password: <input type="password" name="password" /><br><br> <input type="submit" name="submit"/> </form> <?php if(isset($_POST['submit']) && $_POST['submit']) { echo "ok"; $_SESSION['a']="same"; } echo $_SESSION['a']; ?> But each time i load the page, i get the same session values even before i click submit button.. Any Help greatly appreciated.. Thanks in advances Quote Link to comment Share on other sites More sharing options...
MDCode Posted January 13, 2013 Share Posted January 13, 2013 I don't see anywhere that you are setting the session differently. It will always be what you set it to be, no matter what. And you are echoing your session outside of your if(isset()) { ($_POST['submit'] does nothing btw). So on every page load of course it's going to display before you click submit Quote Link to comment Share on other sites More sharing options...
PHP_CHILD Posted January 13, 2013 Author Share Posted January 13, 2013 I don't see anywhere that you are setting the session differently. It will always be what you set it to be, no matter what. And you are echoing your session outside of your if(isset()) { ($_POST['submit'] does nothing btw). So on every page load of course it's going to display before you click submit ok so i want to set a session value after the submit button is clicked... how do i tat... sry am a newbiee.... Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 13, 2013 Share Posted January 13, 2013 (edited) ok so i want to set a session value after the submit button is clicked... how do i tat... sry am a newbiee.... You are doing that. However, I think what you fail to realize is that in the script you provided, once you set the session, it will always echo "same". Once you set a session, it is set for the "session" - which is a configurable time period, but by default it means it will be set for the duration of your browsing visit. If you close your browser, it will clear the session. If this is not the behavior you were looking for, you need to just use a simple variable instead. A variable will only exist for the duration of the script. Edited January 13, 2013 by scootstah Quote Link to comment Share on other sites More sharing options...
PHP_CHILD Posted January 13, 2013 Author Share Posted January 13, 2013 You are doing that. However, I think what you fail to realize is that in the script you provided, once you set the session, it will always echo "same". Once you set a session, it is set for the "session" - which is a configurable time period, but by default it means it will be set for the duration of your browsing visit. If you close your browser, it will clear the session. If this is not the behavior you were looking for, you need to just use a simple variable instead. A variable will only exist for the duration of the script. thank u... tat got me cleared.... Quote Link to comment Share on other sites More sharing options...
PHP_CHILD Posted January 13, 2013 Author Share Posted January 13, 2013 thank u... tat got me cleared.... You are doing that. However, I think what you fail to realize is that in the script you provided, once you set the session, it will always echo "same". Once you set a session, it is set for the "session" - which is a configurable time period, but by default it means it will be set for the duration of your browsing visit. If you close your browser, it will clear the session. If this is not the behavior you were looking for, you need to just use a simple variable instead. A variable will only exist for the duration of the script. i would be grateful if u could tell if der is any other way to navigate between d same page??? 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.