0

I'm lossing the session when I submit a form, until them I kept loged in my code.

I'm sending the session values through the form in that way, but it does not work at all:

<input type='hidden' name='loged' value='".$_SESSION["loged"]."'>
<input type='hidden' name='role' value='".$_SESSION["role"]."'>

Is that right?

Thanks you

of course before I get loged, I alredy worte this on the code:

session_start();

5
  • Why do you need to put session data into form inputs? Why can't you just read it from $_SESSION? Commented Jun 23, 2011 at 10:42
  • to set the value try using "<?php echo $_SESSION['loged']; ?>" Commented Jun 23, 2011 at 10:44
  • If you lose the session data, you're most likely doing something wrong. Can you post a short example to reproduce what is happening? Commented Jun 23, 2011 at 10:44
  • is this part of html code,or php? could you post a little more code? Commented Jun 23, 2011 at 10:45
  • Ok, the main problem is that I lost the session when I execute the submit, but not when I execute a link that point the same place... the main reason I need to use the submit is because when I click the link I execute an specific sql query, and when I do the submit I execute the query but passing what I want to look in the query. If I do so passing the parameter through a link in that why index.php?param=value it works well, but when I execute the submit I get loged out... Commented Jun 23, 2011 at 11:09

2 Answers 2

2

wrong way, you don't need to submit values already set in session

Sign up to request clarification or add additional context in comments.

4 Comments

But My problem is that when I submit the form I lose the session, but if I do anything else, for example, passing parameters through the URL I kept logged.
Here it goes: if($_SESSION["logged"] == "yes" and $_SESSION["role"] == "admin" ){ echo" <form method='post' action=''> <div class='search'> <input type='text' style='color:#f65656' name='char' value=''> </div> <div class='search_submitbox'> <input value='サーチ' type='submit' id='search'> </div> <input type='hidden' name='logged' value='".$_SESSION["logeado"]."'> <input type='hidden' name='role' value='".$_SESSION["role"]."'> </form>";
Ok, the main problem is that I lost the session when I execute the submit, but not when I execute a link that point the same place... the main reason I need to use the submit is because when I click the link I execute an specific sql query, and when I do the submit I execute the query but passing what I want to look in the query. If I do so passing the parameter through a link in that why index.php?param=value it works well, but when I execute the submit I get loged out...
1) remove hidden inputs - 2) add action="your_url" to your <form tag - 3) before you execute search query, check your session values to know if user is allowed - 4) all your scripts must have session_start() to not lose session
0

You are submitting the form ... if you do a phpinfo(); you'll see that the inputs have now arrived as value under $_REQUEST ... If you want to access the session variables again, you need to:

  • session_start();
  • print_r($_SESSION);

You'll see your session vars again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.