mythic Posted January 19, 2009 Share Posted January 19, 2009 I'm new to php, and have only started in fact yesterday. I have worked with php a little before, but only tweaking scripts and messing around till it worked my way. However, yesterday I started my own script. So far so good. I've got it hooked up to the database, I've got a basic login, register, and logout page. The only problem I have, is that in my template, I have a side bar. That's where I keep the login box. I was wondering if anyone new of a tutorial or code that could help me remove the login box if they are logged in, or after they login. so that I can display other info, like their user info and so on. I've tried searching the net but have had no luck, because I have no idea what it'd be called to know what to search for. :S Quote Link to comment Share on other sites More sharing options...
mythic Posted January 19, 2009 Author Share Posted January 19, 2009 I had a look around and I noticed that I could use the else statement, but that only problem is that the login box is in the html, and the php coding is at the top of the page. How could I get around this? Quote Link to comment Share on other sites More sharing options...
Lodius2000 Posted January 19, 2009 Share Posted January 19, 2009 I think its time to see the relevant code from this document Quote Link to comment Share on other sites More sharing options...
9three Posted January 19, 2009 Share Posted January 19, 2009 How are you verifying if the user is logged in? Cookies, Sessions? Your logic code would be: If user is logged in: ->Display something else ->Display HTML form to log in To display an block of HTML you can do echo <<<HTML You can put all the HTML you want here HTML; Quote Link to comment Share on other sites More sharing options...
mike12255 Posted January 19, 2009 Share Posted January 19, 2009 echo <<<HTML You can put all the HTML you want here HTML; you do that to enter html into a php document? Quote Link to comment Share on other sites More sharing options...
mythic Posted January 19, 2009 Author Share Posted January 19, 2009 Okay, this is the coding for the main page sort thing. It's where I have the login info for the sidebar so far. <?php include("conf.inc.php"); //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { // if they are not logged in } ?> <?php include("header.php"); ?> <span class="header">Coming Soon</span><p> <h1> Sorry this page is coming soon. Please check soon! <br><br> </h1> </td> <td width="6" background="images/divider.gif"> </td> <?php include("sidebar.php"); ?> <?php include("footer.php"); ?> And this is the code of the sidebar, where the form is, since it's an include. <td align="center" valign="top" width="200"> <br> <span class="header">Login</span><p> <h1> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan="2" align="right"><h1><a href="register.php">Register</a></h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> </h1> The reason why I don't know how to make it change if they are logged in is because the html code is off else where. It wasn't to begin with. It was mixed in the middle of the php. That's why I don't know how I'd code it to make is disappear, and replace it with something else. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.