fredted40x Posted March 29, 2010 Share Posted March 29, 2010 Hi i have a simple form, <form action="***.php" method="POST"> ***:<br><textarea cols="60" rows="5" name="***"></textarea><br> <input type="submit" value="***"> </form> (have removed names) Is it possible to hide this form if a session has not been created , i have tried using php if ($_SESSION['user']) but the form doesnt run inside the <?php> and ?> tags. Anyone got any sugestions on what could solve this problem? thanks Link to comment https://forums.phpfreaks.com/topic/196855-only-displaying-html-form-if-user-is-logged-in/ Share on other sites More sharing options...
ChemicalBliss Posted March 29, 2010 Share Posted March 29, 2010 Yes PHP is perfect for simple things like this. You almost had it right, here let me help you: Notes: isset() is a function to check wether a variable with the specified name exists at all (even if its empty). empty() is a function to check wether a variable that has been created has data or content. somepage.php <?php session_start(); if(isset($_SESSION['user']) && !empty($_SESSION['user'])){ // Do not dipslay the form is user is logged in: echo("You are already logged in"); }else{ // Show form etc. echo(' <form action="login.php" method="POST"> Username:<br><textarea cols="60" rows="5" name="user"></textarea><br> <input type="submit" value="Login"> </form> '); } ?> login.php <?php if($_POST['user'] == "somevaliduser"){ echo("Logged in, Thanks."); $_SESSION['user'] = $_POST['user']; }else{ echo("Not Authorised"); } ?> Hope this gives you an idea on how php is so powerful. -CB- Link to comment https://forums.phpfreaks.com/topic/196855-only-displaying-html-form-if-user-is-logged-in/#findComment-1033436 Share on other sites More sharing options...
fredted40x Posted March 29, 2010 Author Share Posted March 29, 2010 Thank you! I just missed out the echo and isset, all working now. Link to comment https://forums.phpfreaks.com/topic/196855-only-displaying-html-form-if-user-is-logged-in/#findComment-1033441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.