Jump to content

Online Registration Restricted to Users only NOT WORKING


skiingguru1611

Recommended Posts

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>   

Link to comment
Share on other sites

<!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>   

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

************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']);

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.