Jump to content

Basic session doubt-php beginners


PHP_CHILD

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273094-basic-session-doubt-php-beginners/
Share on other sites

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

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....

 

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.

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....

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???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.