php - Using sessions to confirm login -


i creating page select form that, depending on option selected, display different information.

before user can page must login. continue check if logged in using session otherwise redirect user login. if $_session["admin_username"] exists logged in else not logged in.

the issue trying set session when users go between selection option. set session action in form tag. thought set session if select form used resets wether select form used or not. destroys checking login.

is there way around this? thanks!

here code:

<?php require_once("../include/connection.php"); ?> <?php require_once("../include/functions.php"); ?> <?php require_once("../include/sessions.php"); ?>    <!doctype html public "-//w3c//dtd html 4.01 transitional//en"    "http://www.w3.org/tr/html4/loose.dtd">  <html lang="en"> <style type="text/css">     div {position: relative; left: 300px}     </style>       <head>   <title>databaseconn</title>  </head>  <body>      <h2>welcome, <?php echo (find_user_by_id($_get["user"])["username"]); ?>!</h2>     <?php                if ($_session["admin_username"]) {                 echo "logged in"; } else { redirect_to(login.php); }       <?php       if (isset($_post["submit"])) {          switch ($_post["future"]) {              case "at graduation":                 echo "at graduation";                 break;              case "2 years after graduation":                  echo "2 years after graduation";                  break;              case "5 years after graduation":                  echo "5 years after graduation";                 break;              case "10 years after graduation":                  echo "10 years after graduation";                  break;              case "20 years after graduation":                 echo "20 years after graduation";                 break;              case "50 years after graduation":                  echo "50 years after graduation";                 break;          }      }         echo admin_username();        ?>      <a href="edit_account.php?username=<?php $current_user_id; ?>">edit page</a>            <form action="<?php $_session["admin_username"] = (find_user_by_id($current_user_id)["username"]); ?>" action="main.php?user=<?php echo $current_user_id; ?>" method="post">                <select name="future">                   <option value="at graduation">at graduation</option>                   <option value="2 years after graduation">2 years after graduation 2</option>                   <option value="5 years after graduation">5 years after graduation 2</option>                   <option value="10 years after graduation">10 years after graduation 2</option>                   <option value="20 years after graduation">20 years after graduation 2</option>                   <option value="50 years after graduation">50 years after graduation 2</option>               </select>               <input type="submit" name="submit" value="submit">           </form>     </body> </html> 

here admin_username function use.

function admin_username() {     if (isset($_session["admin_username"])) {         $username = $_session["admin_username"];         $_session["admin_username"] = null;         return $username;     } } 

<form action="<?php $_session["admin_username"] = (find_user_by_id($current_user_id)["username"]); ?>" action="main.php?user=<?php echo $current_user_id; ?>" method="post"> 

on line setting $_session['admin_username'] whatever find_user_by_id($current_user_id)["username"] returns. might mistake in code.

also using action-attribute 2 time.

i don't see usage of admin_username() function in code. when called , supposed do?


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -