Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Unexpected T_Variable?

  1. #1
    burgerking is offline Newbie
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Unhappy Unexpected T_Variable?

    Apparently Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/...session.php on line 332 means that I added something outside of a function within the class Session, but I can't find it.

    Line 332 is a comment, so it must refer to the function preceding it. Here it is, with '...' added in for brevity:

    Code:
    class Session
    ...
    function 
    register($subuser$subpass$subemail,... $subowner){
          global 
    $database$form$mailer;  //The database, form and mailer 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{
             
    /* Spruce up username, check length */
             
    $subuser stripslashes($subuser);
             if(
    strlen($subuser) < 5){
                
    $form->setError($field"* Username below 5 characters");
             }
             else if(
    strlen($subuser) > 30){
                
    $form->setError($field"* Username above 30 characters");
             }
             
    /* Check if username is not alphanumeric */
             
    else if(!eregi("^([0-9a-z])+$"$subuser)){
                
    $form->setError($field"* Username not alphanumeric");
             }
             
    /* Check if username is reserved */
             
    else if(strcasecmp($subuserGUEST_NAME) == 0){
                
    $form->setError($field"* Username reserved word");
             }
             
    /* Check if username is already in use */
             
    else if($database->usernameTaken($subuser)){
                
    $form->setError($field"* Username already in use");
             }
             
    /* Check if username is banned */
             
    else if($database->usernameBanned($subuser)){
                
    $form->setError($field"* Username banned");
             }
          }

          
    /* Password error checking */
          
    $field "pass";  //Use field name for password
          
    if(!$subpass){
             
    $form->setError($field"* Password not entered");
          }
          else{
             
    /* Spruce up password and check length*/
             
    $subpass stripslashes($subpass);
             if(
    strlen($subpass) < 4){
                
    $form->setError($field"* Password too short");
             }
             
    /* Check if password is not alphanumeric */
             
    else if(!eregi("^([0-9a-z])+$", ($subpass trim($subpass)))){
                
    $form->setError($field"* Password not alphanumeric");
             }
          }
          
          
    /* Email error checking */
          
    $field "email";  //Use field name for email
          
    if(!$subemail || strlen($subemail trim($subemail)) == 0){
             
    $form->setError($field"* Email not entered");
          }
          else{
             
    /* Check if valid email address */
             
    $regex "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                     
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                     
    ."\.([a-z]{2,}){1}$";
             if(!
    eregi($regex,$subemail)){
                
    $form->setError($field"* Email invalid");
             }
             
    $subemail stripslashes($subemail);
          }

          
    /* Errors exist, have user correct them */
          
    if($form->num_errors 0){
             return 
    1;  //Errors with form
          
    }
          
    /* No errors, add the new account to the */
          
    else{
             if(
    $database->addNewUser($subusermd5($subpass), $subemail,... $subowner){
                if(
    EMAIL_WELCOME){
                   
    $mailer->sendWelcome($subuser,$subemail,$subpass);
                }
                return 
    0;  //New user added succesfully
             
    }else{
                return 
    2;  //Registration attempt failed
             
    }
          }
       } 
    This error cropped up when I added the owner category to my registration page, SQL database, and scripts, but I don't see the cause of it.

    Is the problem is occurring in another script? Should I post more?

    Thanks in advance!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Unexpected T_Variable?

    What line is 332? The error is probably on line 331 but I cannot say for sure since I dont know what line that is.

  4. #3
    burgerking is offline Newbie
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Re: Unexpected T_Variable?

    That's part of the problem. Line 332 is a comment and line 331 is blank. I posted everything that is just before 332.

  5. #4
    Jordan Guest

    Re: Unexpected T_Variable?

    I see this as a problem:

    Code:
     if($database->addNewUser($subusermd5($subpass), $subemail,... $subowner){ 
    Notice the ...

    If this is not it, please post the entire session.php file.

  6. #5
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Unexpected T_Variable?

    I agree with Jordan. You done it twice.

    Code:
    class Session 
    ...
    Unless that means there is much code before what you posted. Well code between class Session and what you have posted.

    And here.
    Code:
    if($database->addNewUser($subuser, md5($subpass), $subemail,... $subowner){
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

  7. #6
    Jordan Guest

    Re: Unexpected T_Variable?

    I think the first one (between the class and methods) he added to reduce the amount of code pasted. I'm not sure about the second one, it doesn't look like it belongs there.

  8. #7
    burgerking is offline Newbie
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Re: Unexpected T_Variable?

    Here it is, with '...' added in for brevity


    Yes, both of those were added deliberately. There aren't any ellipses in the actual scripts.

    Here is session.php in its entirety, save for some variables that I'd like to keep secret and some lengthy block comments. In this file (though it cannot be run), the error would occur at line 262, so I believe the problem is somewhere in 178-261.

    Code:
    <?
    include("include/database.php");
    include(
    "include/mailer.php");
    include(
    "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

       /* Class constructor */
       
    function Session(){
          
    $this->time time();
          
    $this->startSession();
       }

       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();

          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'];
       }

       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;
          }
       }

       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($subusermd5($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']);

          if(
    $subremember){
             
    setcookie("cookname"$this->usernametime()+COOKIE_EXPIRECOOKIE_PATH);
             
    setcookie("cookid",   $this->userid,   time()+COOKIE_EXPIRECOOKIE_PATH);
          }

          
    /* Login completed successfully */
          
    return true;
       }

       function 
    logout(){
          global 
    $database;  //The database connection
          
    if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
             
    setcookie("cookname"""time()-COOKIE_EXPIRECOOKIE_PATH);
             
    setcookie("cookid",   ""time()-COOKIE_EXPIRECOOKIE_PATH);
          }

          
    /* Unset PHP session variables */
          
    unset($_SESSION['username']);
          unset(
    $_SESSION['userid']);

          
    /* Reflect fact that user has logged out */
          
    $this->logged_in false;
          
          
    /**
           * Remove from active users table and add to
           * active guests tables.
           */
          
    $database->removeActiveUser($this->username);
          
    $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
          
          
    /* Set user level to guest */
          
    $this->username  GUEST_NAME;
          
    $this->userlevel GUEST_LEVEL;
       }

         function 
    register($subuser$subpass$subemail,... $subowner){
          global 
    $database$form$mailer;  //The database, form and mailer 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{
             
    /* Spruce up username, check length */
             
    $subuser stripslashes($subuser);
             if(
    strlen($subuser) < 5){
                
    $form->setError($field"* Username below 5 characters");
             }
             else if(
    strlen($subuser) > 30){
                
    $form->setError($field"* Username above 30 characters");
             }
             
    /* Check if username is not alphanumeric */
             
    else if(!eregi("^([0-9a-z])+$"$subuser)){
                
    $form->setError($field"* Username not alphanumeric");
             }
             
    /* Check if username is reserved */
             
    else if(strcasecmp($subuserGUEST_NAME) == 0){
                
    $form->setError($field"* Username reserved word");
             }
             
    /* Check if username is already in use */
             
    else if($database->usernameTaken($subuser)){
                
    $form->setError($field"* Username already in use");
             }
             
    /* Check if username is banned */
             
    else if($database->usernameBanned($subuser)){
                
    $form->setError($field"* Username banned");
             }
          }

          
    /* Password error checking */
          
    $field "pass";  //Use field name for password
          
    if(!$subpass){
             
    $form->setError($field"* Password not entered");
          }
          else{
             
    /* Spruce up password and check length*/
             
    $subpass stripslashes($subpass);
             if(
    strlen($subpass) < 4){
                
    $form->setError($field"* Password too short");
             }
             
    /* Check if password is not alphanumeric */
             
    else if(!eregi("^([0-9a-z])+$", ($subpass trim($subpass)))){
                
    $form->setError($field"* Password not alphanumeric");
             }
          }
          
          
    /* Email error checking */
          
    $field "email";  //Use field name for email
          
    if(!$subemail || strlen($subemail trim($subemail)) == 0){
             
    $form->setError($field"* Email not entered");
          }
          else{
             
    /* Check if valid email address */
             
    $regex "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                     
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                     
    ."\.([a-z]{2,}){1}$";
             if(!
    eregi($regex,$subemail)){
                
    $form->setError($field"* Email invalid");
             }
             
    $subemail stripslashes($subemail);
          }

          
    /* Errors exist, have user correct them */
          
    if($form->num_errors 0){
             return 
    1;  //Errors with form
          
    }
          
    /* No errors, add the new account to the */
          
    else{
             if(
    $database->addNewUser($subusermd5($subpass), $subemail,...$subowner){
                if(
    EMAIL_WELCOME){
                   
    $mailer->sendWelcome($subuser,$subemail,$subpass);
                }
                return 
    0;  //New user added succesfully
             
    }else{
                return 
    2;  //Registration attempt failed
             
    }
          }
       }
       
       function 
    editAccount($subcurpass$subnewpass$subemail,...$subowner){
          global 
    $database$form;  //The database and form object
          /* New password entered */
          
    if($subnewpass){
             
    /* Current Password error checking */
             
    $field "curpass";  //Use field name for current password
             
    if(!$subcurpass){
                
    $form->setError($field"* Current Password not entered");
             }
             else{
                
    /* Check if password too short or is not alphanumeric */
                
    $subcurpass stripslashes($subcurpass);
                if(
    strlen($subcurpass) < ||
                   !
    eregi("^([0-9a-z])+$", ($subcurpass trim($subcurpass)))){
                   
    $form->setError($field"* Current Password incorrect");
                }
                
    /* Password entered is incorrect */
                
    if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){
                   
    $form->setError($field"* Current Password incorrect");
                }
             }
             
             
    /* New Password error checking */
             
    $field "newpass";  //Use field name for new password
             /* Spruce up password and check length*/
             
    $subpass stripslashes($subnewpass);
             if(
    strlen($subnewpass) < 4){
                
    $form->setError($field"* New Password too short");
             }
             
    /* Check if password is not alphanumeric */
             
    else if(!eregi("^([0-9a-z])+$", ($subnewpass trim($subnewpass)))){
                
    $form->setError($field"* New Password not alphanumeric");
             }
          }
          
    /* Change password attempted */
          
    else if($subcurpass){
             
    /* New Password error reporting */
             
    $field "newpass";  //Use field name for new password
             
    $form->setError($field"* New Password not entered");
          }
          
          
    /* Email error checking */
          
    $field "email";  //Use field name for email
          
    if($subemail && strlen($subemail trim($subemail)) > 0){
             
    /* Check if valid email address */
             
    $regex "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
                     
    ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
                     
    ."\.([a-z]{2,}){1}$";
             if(!
    eregi($regex,$subemail)){
                
    $form->setError($field"* Email invalid");
             }
             
    $subemail stripslashes($subemail);
          }
          
          
    /* Errors exist, have user correct them */
          
    if($form->num_errors 0){
             return 
    false;  //Errors with form
          
    }
          
          
    /* Update password since there were no errors */
          
    if($subcurpass && $subnewpass){
             
    $database->updateUserField($this->username,"password",md5($subnewpass));
          }
          
          
    /* Change Email */
          
    if($subemail){
             
    $database->updateUserField($this->username,"email",$subemail);
          }
          
          
    /* Change User Info */
           
    ...
           
           if(
    $owner){
              
    $database->updateUserField($this->username,"owner",$owner);
           }
          
          
    /* Success! */
          
    return true;
       }
       
       
    /**
        * isAdmin - Returns true if currently logged in user is
        * an administrator, false otherwise.
        */
       
    function isAdmin(){
          return (
    $this->userlevel == ADMIN_LEVEL ||
                  
    $this->username  == ADMIN_NAME);
       }
       
       
    /**
        * generateRandID - Generates a string made up of randomized
        * letters (lower and upper case) and digits and returns
        * the md5 hash of it to be used as a userid.
        */
       
    function generateRandID(){
          return 
    md5($this->generateRandStr(16));
       }
       
       
    /**
        * generateRandStr - Generates a string made up of randomized
        * letters (lower and upper case) and digits, the length
        * is a specified parameter.
        */
       
    function generateRandStr($length){
          
    $randstr "";
          for(
    $i=0$i<$length$i++){
             
    $randnum mt_rand(0,61);
             if(
    $randnum 10){
                
    $randstr .= chr($randnum+48);
             }else if(
    $randnum 36){
                
    $randstr .= chr($randnum+55);
             }else{
                
    $randstr .= chr($randnum+61);
             }
          }
          return 
    $randstr;
       }
    };


    /**
     * Initialize session object - This must be initialized before
     * the form object because the form uses session variables,
     * which cannot be accessed unless the session has started.
     */
    $session = new Session;

    /* Initialize form object */
    $form = new Form;

    ?>

  9. #8
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    Re: Unexpected T_Variable?

    Code:
     if($database->addNewUser($subusermd5($subpass), $subemail,...$subowner){ 
    You forgot an ending ) it should be:
    Code:
    if($database->addNewUser($subusermd5($subpass), $subemail,...$subowner)){ 

  10. #9
    mikelbring is offline Programmer
    Join Date
    Jul 2008
    Location
    Nebraska
    Posts
    118
    Rep Power
    0

    Re: Unexpected T_Variable?

    I hate when those types of errors happen. But using php more and more those errors start to reduce and are easy to find.

  11. #10
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    4,834
    Blog Entries
    10
    Rep Power
    51

    Re: Unexpected T_Variable?

    Yer. The more errors you get the better you will become a programmer.

    Is there anymore errors yet?
    jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation
    Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. JFrame.removeAll gives unexpected behaviour
    By ThemePark in forum Java Help
    Replies: 2
    Last Post: 10-25-2011, 12:54 AM
  2. Unexpected EOFexception
    By toto_7 in forum Java Help
    Replies: 0
    Last Post: 05-17-2011, 12:21 PM
  3. Need help debugging. Unexpected T-ELSE
    By Ascension in forum PHP Development
    Replies: 4
    Last Post: 08-08-2009, 06:52 PM
  4. Unexpected $end
    By Ricardo-san in forum PHP Development
    Replies: 2
    Last Post: 05-31-2009, 05:59 AM
  5. unexpected T_ELSEIF
    By Jaan in forum PHP Development
    Replies: 3
    Last Post: 10-24-2007, 01:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts