skiingguru1611 Posted February 13, 2008 Share Posted February 13, 2008 I THINK WHAT I NEED TO KNOW IS HOW TO INSERT AN HTML FORM INTO AN ECHO FIELD, READ ON FOR MORE INFORMATION. Alright I'm trying to get an online registration form to only show if the user is logged in. I already have the login system set up, along with the form and databases and such. All I need to know I think is how to only have the form show if the user is logged in. The form is written in HTML and I think I need to put that into an echo after the line: if($session->logged_in){ Anyways take a look and let me know, if you don't understand tell me what you don't get about the question and I'll try to explain it better. Thank You. Here is the code for the online registration file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> </html> <? include("../Login/session.php"); ?> <? if($session->logged_in){ } ?> <html> <body> <form method="post" action="insert.php"> <p>First Name <input type="text" name="first" size="20"> Last <input type="text" name="last" size="20"></p> <p>Address <input type="text" name="address" size="20"> City<input type="text" name="city" size="20"> State <input type="text" name="state" size="20"> Zipcode <input type="text" name="zipcode" size="20"></p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" size="20"> Cell Phone <input type="text" name="cell" size="20"> </p> <p>Email <input type="text" name="email" size="20"> </p> <p>Age<input type="text" name="age" size="20"> Weight <input type="text" name="weight1" size="20"> Height <input type="text" name="height1" size="20"> Grade Sept. '08 <input type="text" name="grade" size="20"></p> <p>Position: <input type="text" name="position"></p> <p>School <input type="text" name="school" size="20"> Level of Play in '07 <input type="text" name="level" size="20"> Coach's Name <input type="text" name="coach" size="20"></p> <p><input type="submit" value="Send"></p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/ Share on other sites More sharing options...
laffin Posted February 13, 2008 Share Posted February 13, 2008 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <? include("../Login/session.php"); ?> <? if($session->logged_in){ ?> <form method="post" action="insert.php"> <p>First Name <input type="text" name="first" size="20"> Last <input type="text" name="last" size="20"></p> <p>Address <input type="text" name="address" size="20"> City<input type="text" name="city" size="20"> State <input type="text" name="state" size="20"> Zipcode <input type="text" name="zipcode" size="20"></p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" size="20"> Cell Phone <input type="text" name="cell" size="20"> </p> <p>Email <input type="text" name="email" size="20"> </p> <p>Age<input type="text" name="age" size="20"> Weight <input type="text" name="weight1" size="20"> Height <input type="text" name="height1" size="20"> Grade Sept. '08 <input type="text" name="grade" size="20"></p> <p>Position: <input type="text" name="position"></p> <p>School <input type="text" name="school" size="20"> Level of Play in '07 <input type="text" name="level" size="20"> Coach's Name <input type="text" name="coach" size="20"></p> <p><input type="submit" value="Send"></p> </form> <? } else echo { ?><H2>Must be logged in</h2> <? } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466371 Share on other sites More sharing options...
skiingguru1611 Posted February 13, 2008 Author Share Posted February 13, 2008 Thanks for the fast reply. But it gives me this error Parse error: syntax error, unexpected '{' in /home/tullyl00/domains/skiingguru1611.com/public_html/onlinereg.php on line 28 Below are lines 28-31 28. <? } else echo { 29. ?><H2>Must be logged in</h2> 30. <? } 31. ?> Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466376 Share on other sites More sharing options...
laffin Posted February 13, 2008 Share Posted February 13, 2008 oops shud be } else { sumtimes brain dun catch errors created by fingers Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466377 Share on other sites More sharing options...
skiingguru1611 Posted February 13, 2008 Author Share Posted February 13, 2008 Once again thank you. The code for the file is now this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <? include("../Login/session.php"); ?> <? if($session->logged_in){ ?> <form method="post" action="insert.php"> <p>First Name <input type="text" name="first" size="20"> Last <input type="text" name="last" size="20"></p> <p>Address <input type="text" name="address" size="20"> City<input type="text" name="city" size="20"> State <input type="text" name="state" size="20"> Zipcode <input type="text" name="zipcode" size="20"></p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" size="20"> Cell Phone <input type="text" name="cell" size="20"> </p> <p>Email <input type="text" name="email" size="20"> </p> <p>Age<input type="text" name="age" size="20"> Weight <input type="text" name="weight1" size="20"> Height <input type="text" name="height1" size="20"> Grade Sept. '08 <input type="text" name="grade" size="20"></p> <p>Position: <input type="text" name="position"></p> <p>School <input type="text" name="school" size="20"> Level of Play in '07 <input type="text" name="level" size="20"> Coach's Name <input type="text" name="coach" size="20"></p> <p><input type="submit" value="Send"></p> </form> <? } else { echo ?><h2>Must be logged in</h2> <? } ?> </body> </html> But now i get this error. Parse error: syntax error, unexpected ';' in /home/tullyl00/domains/skiingguru1611.com/public_html/onlinereg.php on line 29 But i don't see where thats coming from, theres no ; on line 29 as far as I see. I'm new to PHP though to I'm probably just not seeing something. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466383 Share on other sites More sharing options...
skiingguru1611 Posted February 14, 2008 Author Share Posted February 14, 2008 ************NEW QUESTION************ Or explain whats wrong with file from previous post^^^^ I changed the onlinereg.php file to: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <? include("../Login/session.php"); ?> <? if($session->logged_in){ ?> <form method="post" action="insert.php"> <p>First Name <input type="text" name="first" size="20"> Last <input type="text" name="last" size="20"></p> <p>Address <input type="text" name="address" size="20"> City<input type="text" name="city" size="20"> State <input type="text" name="state" size="20"> Zipcode <input type="text" name="zipcode" size="20"></p> <p>Phone ex.(555) 555-5555 <input type="text" name="phone" size="20"> Cell Phone <input type="text" name="cell" size="20"> </p> <p>Email <input type="text" name="email" size="20"> </p> <p>Age<input type="text" name="age" size="20"> Weight <input type="text" name="weight1" size="20"> Height <input type="text" name="height1" size="20"> Grade Sept. '08 <input type="text" name="grade" size="20"></p> <p>Position: <input type="text" name="position"></p> <p>School <input type="text" name="school" size="20"> Level of Play in '07 <input type="text" name="level" size="20"> Coach's Name <input type="text" name="coach" size="20"></p> <p><input type="submit" value="Send"></p> </form> <? } else{ ?> <h2>Must be logged in</h2> <? } ?> </body> </html> But I get this error: Warning: include(../Login/session.php) [function.include]: failed to open stream: No such file or directory in /home/tullyl00/domains/skiingguru1611.com/public_html/onlinereg.php on line 9 Warning: include() [function.include]: Failed opening '../Login/session.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/tullyl00/domains/skiingguru1611.com/public_html/onlinereg.php on line 9 By the way session.php looks like: (this is only part of the file you need to see, i believe the rest is irrelevent for this problem) <? /** * Session.php * * The Session class is meant to simplify the task of keeping * track of logged in users and also guests. * * Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC) * Last Updated: August 19, 2004 */ include("database.php"); include("mailer.php"); include("form.php"); class Session { var $username; //Username given on sign-up var $userid; //Random value generated on current login var $userlevel; //The level to which the user pertains var $time; //Time user was last active (page loaded) var $logged_in; //True if user is logged in, false otherwise var $userinfo = array(); //The array holding all user info var $url; //The page url current being viewed var $referrer; //Last recorded site page viewed /** * Note: referrer should really only be considered the actual * page referrer in process.php, any other time it may be * inaccurate. */ /* Class constructor */ function Session(){ $this->time = time(); $this->startSession(); } /** * startSession - Performs all the actions necessary to * initialize this session object. Tries to determine if the * the user has logged in already, and sets the variables * accordingly. Also takes advantage of this page load to * update the active visitors tables. */ function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); /** * Set guest value to users not logged in, and update * active guests table accordingly. */ if(!$this->logged_in){ $this->username = $_SESSION['username'] = GUEST_NAME; $this->userlevel = GUEST_LEVEL; $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time); } /* Update users last active timestamp */ else{ $database->addActiveUser($this->username, $this->time); } /* Remove inactive visitors from database */ $database->removeInactiveUsers(); $database->removeInactiveGuests(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } /** * checkLogin - Checks if the user has already previously * logged in, and a session with the user has already been * established. Also checks to see if user has been remembered. * If so, the database is queried to make sure of the user's * authenticity. Returns true if the user has logged in. */ function checkLogin(){ global $database; //The database connection /* Check if user has been remembered */ if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){ $this->username = $_SESSION['username'] = $_COOKIE['cookname']; $this->userid = $_SESSION['userid'] = $_COOKIE['cookid']; } /* Username and userid have been set and not guest */ if(isset($_SESSION['username']) && isset($_SESSION['userid']) && $_SESSION['username'] != GUEST_NAME){ /* Confirm that username and userid are valid */ if($database->confirmUserID($_SESSION['username'], $_SESSION['userid']) != 0){ /* Variables are incorrect, user not logged in */ unset($_SESSION['username']); unset($_SESSION['userid']); return false; } /* User is logged in, set class variables */ $this->userinfo = $database->getUserInfo($_SESSION['username']); $this->username = $this->userinfo['username']; $this->userid = $this->userinfo['userid']; $this->userlevel = $this->userinfo['userlevel']; return true; } /* User not logged in */ else{ return false; } } /** * login - The user has submitted his username and password * through the login form, this function checks the authenticity * of that information in the database and creates the session. * Effectively logging in the user if all goes well. */ function login($subuser, $subpass, $subremember){ global $database, $form; //The database and form object /* Username error checking */ $field = "user"; //Use field name for username if(!$subuser || strlen($subuser = trim($subuser)) == 0){ $form->setError($field, "* Username not entered"); } else{ /* Check if username is not alphanumeric */ if(!eregi("^([0-9a-z])*$", $subuser)){ $form->setError($field, "* Username not alphanumeric"); } } /* Password error checking */ $field = "pass"; //Use field name for password if(!$subpass){ $form->setError($field, "* Password not entered"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Checks that username is in database and password is correct */ $subuser = stripslashes($subuser); $result = $database->confirmUserPass($subuser, md5($subpass)); /* Check error codes */ if($result == 1){ $field = "user"; $form->setError($field, "* Username not found"); } else if($result == 2){ $field = "pass"; $form->setError($field, "* Invalid password"); } /* Return if form errors exist */ if($form->num_errors > 0){ return false; } /* Username and password correct, register session variables */ $this->userinfo = $database->getUserInfo($subuser); $this->username = $_SESSION['username'] = $this->userinfo['username']; $this->userid = $_SESSION['userid'] = $this->generateRandID(); $this->userlevel = $this->userinfo['userlevel']; /* Insert userid into database and update active users table */ $database->updateUserField($this->username, "userid", $this->userid); $database->addActiveUser($this->username, $this->time); $database->removeActiveGuest($_SERVER['REMOTE_ADDR']); Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466396 Share on other sites More sharing options...
schilly Posted February 14, 2008 Share Posted February 14, 2008 <? include("../Login/session.php"); ?> needs to be at the top of page before any html. Also check the pathname of the session.php file. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466401 Share on other sites More sharing options...
skiingguru1611 Posted February 14, 2008 Author Share Posted February 14, 2008 I moved it to the top but it gives me the same error (but a different line, as to be expected). It's the right pathname as well. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466407 Share on other sites More sharing options...
skiingguru1611 Posted February 14, 2008 Author Share Posted February 14, 2008 I have found the problem and fixed it. Thank you both very much that helped me. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466430 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 includes don't have to be at the top or before HTML. The problem was the leading / <? include("../Login/session.php"); ?> needs to be at the top of page before any html. Also check the pathname of the session.php file. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466443 Share on other sites More sharing options...
legohead6 Posted February 14, 2008 Share Posted February 14, 2008 its time to use some common sence, you should be able to figure out alot of these errors on your own, if not then this is too advanced for you skill level for example <? } else { echo ?><h2>Must be logged in</h2> <? } thats around line 29.. it says missing ';' hopefully you can figure out that its saying... also it would make it alot easier for you if you just use php to echo the html, having the php starting and stoping so much is going to make it challanging.. i would compact down all the html into 1 echo, then use a variable to decide on the error messages, etc, or even another echo, but having all those php start/stops is not very effective... Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466449 Share on other sites More sharing options...
schilly Posted February 14, 2008 Share Posted February 14, 2008 Sorry. Meant that because it had to do with sessions. includes don't have to be at the top or before HTML. The problem was the leading / <? include("../Login/session.php"); ?> needs to be at the top of page before any html. Also check the pathname of the session.php file. Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-466809 Share on other sites More sharing options...
skiingguru1611 Posted February 14, 2008 Author Share Posted February 14, 2008 You need to calm down, I said I figured it out. Anyways I just started learning PHP a couple days ago so chill. It's not too advanced, I just didn't know how to incorporate HTML into an echo, which I figured out with a little help. And I believe this is the "PHP Help" Section, so if you don't have anything useful to say, don't post. its time to use some common sence, you should be able to figure out alot of these errors on your own, if not then this is too advanced for you skill level for example <? } else { echo ?><h2>Must be logged in</h2> <? } thats around line 29.. it says missing ';' hopefully you can figure out that its saying... also it would make it alot easier for you if you just use php to echo the html, having the php starting and stoping so much is going to make it challanging.. i would compact down all the html into 1 echo, then use a variable to decide on the error messages, etc, or even another echo, but having all those php start/stops is not very effective... Quote Link to comment https://forums.phpfreaks.com/topic/90995-online-registration-restricted-to-users-only-not-working/#findComment-467127 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.