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

Link to comment
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

ok so i want to set a session value after the submit button is clicked... how do i tat... sry am a newbiee....

Link to comment
Share on other sites

 

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 by scootstah
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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