First of all I'm completely ignorant when it comes to PHP with that said here is my problem... Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/jlennon/public_html/wetbar/drinks/includes/auth.php on line 29 If anyone could help me with this I would be very greatfull. Here's the code for auth.php <?php /* @author Steve Riesenberg *** class Auth created by gutting code found on PHPBuilder.com *** This is a user authentication abstraction layer. Due to the nature of user authentication, it is difficult to abstract very much, so this class has configureable variables to take care of this common problem. *** It also assumes that a global $db object has been created using the DB database abstraction layer. */ //allows you to dynamically change sql statement to meet your needs define('USER_TABLE',"users"); define('USER_ID_FIELD',"user_id"); define('USERNAME_FIELD',"username"); define('USER_PASSWORD_FIELD',"user_password"); define('USER_EMAIL_FIELD',"user_email"); define('USER_ACTIVE_FIELD',"user_active"); define('USER_STYLE_FIELD',"user_style"); define('USER_HASH_FIELD',"user_actkey"); define('SESSION_ID_FIELD',"session_id"); define('SESSION_STRING_FIELD',"session_string"); define('COMMA',","); class Auth { private $hidden_hash_var='zizzy_baluba'; //not my idea private $user_id; private $id_hash; private $userdata; private $feedback; private $session_name='auth_session'; function Auth() { session_name($this->session_name); session_start(); //asks user-cookie and database for stored session; if found, it is restored (i.e. "automatically log me in") $this->restore_saved_session(); $this->user_id=$_SESSION['user_id']==''?ANONYMOUS:$_SESSION['user_id']; $this->id_hash=$_SESSION['id_hash']; $this->populate_info(); } function is_logged_in() { if ($this->user_id && $this->id_hash) { $hash=md5($this->user_id.$this->hidden_hash_var); if ($hash == $this->id_hash) { // ...&& $this->user_id != ANONYMOUS) [taken care of by "if (... && $this->id_hash)"] return true; } } return false; } function login($username,$password,$save_session=false) { global $db; if (!$username || !$password) { $this->feedback .= ' ERROR - Missing user name or password <br> '; return false; } else { $username=strtolower($username); $password=strtolower($password); $sql="SELECT ".USER_ID_FIELD.COMMA.USERNAME_FIELD." FROM ".USER_TABLE. " WHERE ".USERNAME_FIELD."='$username' AND ".USER_PASSWORD_FIELD."='". md5($password) ."'"; $result=$db->sql_query($sql); if (!$result || $db->sql_numrows($result) < 1){ $this->feedback .= ' ERROR - User not found or password incorrect <br> '; $this->logout(); return false; } else {// if ( $db->sql_numrows($result) >= 1) { $this->feedback .= ' SUCCESS - You Are Now Logged In <br> '; //repeat the steps done by constructor, but overriding values with logged in values $this->user_id=$db->sql_fetchfield($this->user_id_field,0,$result); $this->id_hash=md5($this->user_id.$this->hidden_hash_var); //set session cookies and populate userdata array $this->set_tokens(); $this->populate_info(); if ($this->userdata[USER_ACTIVE_FIELD] == 0) { $this->feedback .= ' ERROR - You Account is Inactive <br> '; $this->logout(); return false; } //saves users session with profile if user wants session saved ("log me in automatically") $this->save_session($save_session); return true; } } } function logout() { $this->feedback .= ' SUCCESS - You Are Now Logged Out <br> '; unset($_SESSION['id_hash']); unset($_SESSION['user_id']); //if no session_id_hash found, session will not be restored on return, even if saved in the database if (isset($_COOKIE['session_id_hash'])) { setcookie('session_id_hash','0',time()+60*60*24*365);//unset($_COOKIE['session_id_hash']); } //$_SESSION = array(); $this->populate_info(); return true; } private function set_tokens() { $_SESSION['id_hash']=$this->id_hash; $_SESSION['user_id']=$this->user_id; } //pre: session user_id cookie must be set to valid user_id or blank/unset (ANONYMOUS) //pre: id_hash cookie must be set or blank/unset (ANONYMOUS) //post: all variables are set for user or ANONYMOUS private function populate_info() { global $db; $sql="SELECT * FROM ".USER_TABLE." WHERE ".USER_ID_FIELD."='$this->user_id'"; $result=$db->sql_query($sql); //creates an array with key=>value data for user $this->userdata=$db->sql_fetchrow($result); $this->userdata['session_logged_in']=$this->is_logged_in(); $this->userdata['session_id']=session_id(); } private function save_session($save_session) { global $db; //does user want session saved with profile? if ($save_session) { $this->feedback .= ' SUCCESS - Session Saved <br> '; $sess_string=session_encode(); $session_id_hash=md5(session_id().$this->hidden_hash_var); $sql="UPDATE ".USER_TABLE." SET ".SESSION_ID_FIELD."='$session_id_hash', ".SESSION_STRING_FIELD."='$sess_string' WHERE ".USER_ID_FIELD."='$this->user_id'"; $result=$db->sql_query($sql); //external cookie var not associated with PHP session, for restoring saved session setcookie('session_id_hash',$session_id_hash,time()+60*60*24*365); return true; } return false; } private function restore_saved_session() { global $db; //external cookie var not associated with PHP session, for restoring saved session $session_id_hash=$_COOKIE['session_id_hash']; //is there a session to restore? if ($session_id_hash && $session_id_hash != '0') { $sql="SELECT ".USER_ID_FIELD.COMMA.USERNAME_FIELD.COMMA.SESSION_STRING_FIELD." FROM ".USER_TABLE. " WHERE ".SESSION_ID_FIELD."='$session_id_hash'"; $result=$db->sql_query($sql); if ($db->sql_numrows($result) > 0) { //$row=$db->sql_fetchrow($result); $sess_string=$db->sql_fetchfield(SESSION_STRING_FIELD,0,$result); //replace $_SESSION array with serialized session data from $sess_string $new_session = $this->decode_session($sess_string); if ($new_session) { $_SESSION = $new_session; $this->feedback .= ' SUCCESS - Session Restored <br> '; return true; } } } return false; } function register($username,$password1,$password2,$email,$style=1,$confirm_user=false) { global $db; //all vars present and passwords match? if ($username && $password1 && $password1 == $password2 && $email && $this->validate_email($email)) { //password and name are valid? if ($this->account_namevalid($username) && $this->account_pwvalid($password1)) { $username=strtolower($username); $password1=strtolower($password1); $active=$confirm_user?0:1; //does the name exist in the database? account_namevalid() did this already! //create a new hash to insert into the db and the confirmation email $hash=md5($email.$this->hidden_hash_var); $sql="INSERT INTO ".USER_TABLE." (".USERNAME_FIELD.COMMA.USER_PASSWORD_FIELD.COMMA.USER_EMAIL_FIELD.COMMA. USER_HASH_FIELD.COMMA.USER_STYLE_FIELD.COMMA.USER_ACTIVE_FIELD.") VALUES ('$username','". md5($password1) ."','$email','$hash',$style,$active)"; $result=$db->sql_query($sql); if (!$result) { $this->feedback .= ' ERROR - '.$db->sql_error(); return false; } else { //send the confirm email $sendmail=$this->send_confirm_email($email,$hash); if ($sendmail) { $this->feedback .= ' Successfully Registered. You Should Have a Confirmation Email Waiting <br> '; return true; } return false; } } else { $this->feedback .= ' Account Name or Password Invalid <br> '; return false; } } else { $this->feedback .= ' ERROR - Must Fill In User Name, Matching Passwords, And Provide Valid Email Address <br> '; return false; } } private function account_pwvalid($pw) { if (strlen($pw) < 6) { $this->feedback .= " Password must be at least 6 characters. "; return false; } return true; } private function account_namevalid($name) { global $db; // no spaces if (strrpos($name,' ') > 0) { $this->feedback .= " There cannot be any spaces in the login name. "; return false; } // must have at least one character if (strspn($name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") == 0) { $this->feedback .= "There must be at least one character."; return false; } // must contain all legal characters if (strspn($name,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_") != strlen($name)) { $this->feedback .= " Illegal character in name. "; return false; } // min and max length if (strlen($name) < 5) { $this->feedback .= " Name is too short. It must be at least 5 characters. "; return false; } if (strlen($name) > 15) { $this->feedback .= " Name is too long. It must be less than 15 characters. "; return false; } // illegal names if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)" . "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)" . "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$name)) { $this->feedback .= " Name is reserved. "; return 0; } if (eregi("^(anoncvs_)",$name)) { $this->feedback .= " Name is reserved for CVS. "; return false; } $sql="SELECT ".USERNAME_FIELD." FROM ".USER_TABLE." WHERE ".USERNAME_FIELD."='$username'"; $result=$db->sql_query($sql); if ($result && $db->sql_numrows($result) > 0) { $this->feedback .= " Name exists already. "; return false; } return true; } private function send_confirm_email($email,$hash) { /* Used in the initial registration function as well as the change email address function */ $message="Thank You For Registering". "\nSimply follow this link to confirm your registration: ". "\n\nhttp://mydomain.com/my_confirm_page.php?hash=$hash&email=". urlencode($email); $result = @mail($email,'Registration Confirmation',$message,'stephen.riesenberg@usd.edu'); if (!$result) { $this->feedback = ' ERROR - Failed Sending Message :: ' . $result; return false; } return true; } function confirm($email,$hash) { /* Call this function on the user confirmation page, which they arrive at when they click the link in the account confirmation email */ global $db; //verify that they didn't tamper with the email address $new_hash=md5($email.$this->hidden_hash_var); if ($new_hash && ($new_hash ==$hash)) { //find this record in the db $sql="SELECT ".USERNAME_FIELD.COMMA.USER_ID_FIELD." FROM ".USER_TABLE." WHERE ".USER_HASH_FIELD."='$hash'"; $result=$db->sql_query($sql); if (!$result || $db->sql_numrows($result) < 1) { $this->feedback .= ' ERROR - Hash Not Found <br> '; return false; } else { //confirm the email and set account to active $this->feedback .= ' User Account Updated - You Are Now Logged In <br> '; //Logging in, but without the password, since $hash from email validated $row=$db->sql_fetchrowset($result); $this->user_id=$db->sql_fetchfield('user_id'); $this->id_hash=md5($this->username.$this->hidden_hash_var); $this->set_tokens(); $this->populate_info(); //Set user active in database $sql="UPDATE ".USER_TABLE." SET ".USER_EMAIL_FIELD."='$email', ".USER_ACTIVE_FIELD."=1 WHERE ".USER_HASH_FIELD."='$hash'"; $result=$db->sql_query($sql); return true; } } else { $this->feedback .= ' HASH INVALID - UPDATE FAILED <br> '; return false; } } function change_password($change_username,$old_password,$new_password1,$new_password2) { global $db; //new passwords present and match? if ($new_password1 && ($new_password1 ==$new_password2)) { //is this password long enough? if (account_pwvalid($new_password1)) { //all vars are present? if ($change_username && $old_password) { //lower case everything $change_username=strtolower($change_username); $old_password=strtolower($old_password); $new_password1=strtolower($new_password1); $sql="SELECT ".USERNAME_FIELD.COMMA.USER_ID_FIELD." FROM ".USER_TABLE. " WHERE ".USERNAME_FIELD."='$change_username' AND ".USER_PASSWORD_FIELD."='". md5($old_password) ."'"; $result=$db->sql_query($sql); if (!$result || $db->sql_numrows($result) < 1) { $this->feedback .= ' User not found or bad password '.mysql_error(); return false; } else { $sql="UPDATE ".USER_TABLE." SET ".USER_PASSWORD_FIELD."='". md5($new_password1). "' ". " WHERE ".USERNAME_FIELD."='$change_username' AND ".USER_PASSWORD_FIELD."='". md5($old_password). "'"; $result=$db->sql_query($sql); if (!$result || $db->sql_affectedrows($result) < 1) { $this->feedback .= ' NOTHING Changed '.db_error(); return false; } else { $this->feedback .= ' Password Changed <br> '; return true; } } } else { $this->feedback .= ' Must Provide User Name And Old Password <br> '; return false; } } else { $this->feedback .= ' New Passwords Doesn\'t Meet Criteria <br> '; return false; } } else { $this->feedback .= ' New Passwords Must Match <br> '; return false; } } function lost_password($username,$email) { global $db; if ($email && $username) { $username=strtolower($username); $sql="SELECT ".USERNAME_FIELD." FROM ".USER_TABLE. " WHERE ".USERNAME_FIELD."='$username' AND ".USER_EMAIL_FIELD."='$email'"; $result=$db->sqlquery($sql); if (!$result || $db->sql_numrows($result) < 1) { //no matching user found $this->feedback .= ' ERROR - Incorrect User Name Or Email Address <br> '; return false; } else { //create a secure, new password $new_pass=strtolower(substr(md5(time().$username.$this->hidden_hash_var),1,14)); //update the database to include the new password $sql="UPDATE ".USER_TABLE." SET ".USER_PASSWORD_FIELD."='". md5($new_pass) . "' WHERE ".USERNAME_FIELD."='$username'"; $result=$db->sql_query($sql); //send a simple email with the new password @mail ($email,'Password Reset','Your Password '. 'has been reset to: '.$new_pass,'From: noreply@mydomain.com'); $this->feedback .= ' Your new password has been emailed to you. <br> '; return true; } } else { $this->feedback .= ' ERROR - User Name and Email Address Are Required <br> '; return false; } } function change_email($username,$password1,$new_email) { global $db; if (validate_email($new_email)) { $hash=md5($new_email.$this->hidden_hash_var); //change the confirm hash in the db but not the email - //send out a new confirm email with a new hash $username=strtolower($username); $password1=strtolower($password1); $sql="UPDATE ".USER_TABLE." SET ".USER_HASH_FIELD."='$hash' WHERE ".USERNAME_FIELD."='$username' AND ".USER_PASSWORD_FIELD."='". md5($password1) ."'"; $result=$db->sql_query($sql); if (!$result || $db->sql_affectedrows($result) < 1) { $this->feedback .= ' ERROR - Incorrect User Name Or Password <br> '; return false; } else { $this->feedback .= ' Confirmation Sent <br> '; send_confirm_email($new_email,$hash); return true; } } else { $this->feedback .= ' New Email Address Appears Invalid <br> '; return false; } } function validate_email($address) { return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address)); } // returns decoded string as arrays of variables // or false on error (when session_decode returns false) //from user-comments: http://us3.php.net/manual/en/function.session-decode.php private function decode_session($sess_string) { // save current session data // and flush $_SESSION array $old=$_SESSION; $_SESSION=array(); // try to decode passed string $ret=session_decode($sess_string); if (!$ret) { // if passed string is not session data, // retrieve saved (old) session data // and return false $_SESSION=array(); $_SESSION=$old; return false; } // save decoded session data to sess_array // and flush $_SESSION array $sess_array=$_SESSION; $_SESSION=array(); // restore old session data $_SESSION=$old; // return decoded session data return $sess_array; } function get_user_id() { return $this->user_id; } function get_userdata_value($key) { return $this->userdata[$key]; } function get_userdata() { return $this->userdata; } function get_feedback() { return $this->feedback; } } ?> PHP:
There's nothing wrong with the code. It's your PHP version. Upgrade to PHP 5. Check your control panel if there's an option to switch between PHP 4 and PHP 5. if there isn't, email your host and tell them to upgrade. The support for PHP 4 ends this year. So they'll be forced to upgrade sooner or later anyway. Source: http://www.php.net/index.php#2007-07-13-1
I upgraded to PHP 5 and now I get this error Drinks : Critical_Error Could not query config information DEBUG MODE SQL Error : 1146 Table 'jlennon_drinks.config' doesn't exist SELECT * FROM config Line : 309 File : common.php I'm trying to install phpWetBar on my site. I think I have the error because... Actually I have no idea why Can I pay someone to install this for me?
It's simply telling you that the database table doesn't exist. Have a look if there's an install.php file or similar, which installs the tables. Or look if there's a .txt/.sql file which holds the tables.
Thanks nico_swd The install instructions ask me to create a database and name it 'drinks' My hosting provider adds 'jlennon_' so the database becomes 'jlennon_drinks' I changed the database name in the .sql file so it would match. Also I have the .sql file in the root directory and all other files in a folder Anyway here's the code * FROM config in the .sql file I really wish I knew more about this stuff but I don't and can't spend a lot of time trying to figure it out. I would love to fix it if it's easy but if it not, oh well have to move on. Thanks for any suggestions... -- -------------------------------------------------------- -- -- Table structure for table `config` -- DROP TABLE IF EXISTS `config`; CREATE TABLE `config` ( `config_name` varchar(255) NOT NULL default '', `config_value` varchar(255) NOT NULL default '', PRIMARY KEY (`config_name`) ) ENGINE=MyISAM DEFAULT CHARSET=ascii; -- -- Dumping data for table `config` -- INSERT INTO `config` VALUES ('allow_avatar_local', '1'); INSERT INTO `config` VALUES ('allow_avatar_remote', '1'); INSERT INTO `config` VALUES ('allow_avatar_upload', '1'); INSERT INTO `config` VALUES ('allow_bbcode', '1'); INSERT INTO `config` VALUES ('allow_html', '1'); INSERT INTO `config` VALUES ('allow_html_tags', ''); INSERT INTO `config` VALUES ('allow_namechange', '1'); INSERT INTO `config` VALUES ('allow_sig', '1'); INSERT INTO `config` VALUES ('allow_smilies', '1'); INSERT INTO `config` VALUES ('allow_theme_create', '0'); INSERT INTO `config` VALUES ('avatar_filesize', '80000'); INSERT INTO `config` VALUES ('avatar_gallery_path', 'images/avatars/gallery'); INSERT INTO `config` VALUES ('avatar_max_height', '200'); INSERT INTO `config` VALUES ('avatar_max_width', '200'); INSERT INTO `config` VALUES ('avatar_path', 'images/avatars'); INSERT INTO `config` VALUES ('bibletype', 'NIV'); INSERT INTO `config` VALUES ('board_disable', '0'); INSERT INTO `config` VALUES ('board_email', 'admin@domain.com'); INSERT INTO `config` VALUES ('board_email_form', '1'); INSERT INTO `config` VALUES ('board_email_sig', ''); INSERT INTO `config` VALUES ('board_startdate', '9694509999'); INSERT INTO `config` VALUES ('board_timezone', '-6'); INSERT INTO `config` VALUES ('config_id', '1'); INSERT INTO `config` VALUES ('cookie_domain', ''); INSERT INTO `config` VALUES ('cookie_name', 'drinksmysql'); INSERT INTO `config` VALUES ('cookie_path', '/'); INSERT INTO `config` VALUES ('cookie_secure', '0'); INSERT INTO `config` VALUES ('coppa_fax', ''); INSERT INTO `config` VALUES ('coppa_mail', ''); INSERT INTO `config` VALUES ('default_dateformat', 'D M d Y, g:i A'); INSERT INTO `config` VALUES ('default_lang', 'english'); INSERT INTO `config` VALUES ('default_style', '1'); INSERT INTO `config` VALUES ('enable_confirm', '0'); INSERT INTO `config` VALUES ('flood_interval', '20'); INSERT INTO `config` VALUES ('forum_icon_path', 'images'); INSERT INTO `config` VALUES ('gzip_compress', '0'); INSERT INTO `config` VALUES ('hot_threshold', '10'); INSERT INTO `config` VALUES ('liw_attach_enabled', '1'); INSERT INTO `config` VALUES ('liw_enabled', '1'); INSERT INTO `config` VALUES ('liw_max_width', '500'); INSERT INTO `config` VALUES ('liw_sig_enabled', '1'); INSERT INTO `config` VALUES ('max_inbox_privmsgs', '50'); INSERT INTO `config` VALUES ('max_poll_options', '10'); INSERT INTO `config` VALUES ('max_savebox_privmsgs', '50'); INSERT INTO `config` VALUES ('max_sentbox_privmsgs', '50'); INSERT INTO `config` VALUES ('max_sig_chars', '255'); INSERT INTO `config` VALUES ('override_user_style', '0'); INSERT INTO `config` VALUES ('posts_per_page', '15'); INSERT INTO `config` VALUES ('privmsg_disable', '0'); INSERT INTO `config` VALUES ('prune_enable', '1'); INSERT INTO `config` VALUES ('record_online_date', '1112753850'); INSERT INTO `config` VALUES ('record_online_users', '8'); INSERT INTO `config` VALUES ('require_activation', '0'); INSERT INTO `config` VALUES ('script_path', '/drinks'); INSERT INTO `config` VALUES ('sendmail_fix', '1'); INSERT INTO `config` VALUES ('server_name', 'localhost'); INSERT INTO `config` VALUES ('server_port', '80'); INSERT INTO `config` VALUES ('session_length', '3600'); INSERT INTO `config` VALUES ('sitename', 'phpWetBar'); INSERT INTO `config` VALUES ('site_desc', 'The Wet Bar'); INSERT INTO `config` VALUES ('smilies_path', 'images/smiles'); INSERT INTO `config` VALUES ('smtp_delivery', '0'); INSERT INTO `config` VALUES ('smtp_host', ''); INSERT INTO `config` VALUES ('smtp_password', ''); INSERT INTO `config` VALUES ('smtp_username', ''); INSERT INTO `config` VALUES ('topics_per_page', '50'); INSERT INTO `config` VALUES ('version', '.0.15'); INSERT INTO `config` VALUES ('xs_add_comments', '0'); INSERT INTO `config` VALUES ('xs_auto_compile', '1'); INSERT INTO `config` VALUES ('xs_auto_recompile', '1'); INSERT INTO `config` VALUES ('xs_check_switches', '1'); INSERT INTO `config` VALUES ('xs_def_template', 'subSilver'); INSERT INTO `config` VALUES ('xs_downloads_count', '0'); INSERT INTO `config` VALUES ('xs_downloads_default', '0'); INSERT INTO `config` VALUES ('xs_ftp_host', 'chersterz.servebeer.com'); INSERT INTO `config` VALUES ('xs_ftp_login', 'drinks'); INSERT INTO `config` VALUES ('xs_ftp_path', 'htdocs/drinks'); INSERT INTO `config` VALUES ('xs_php', 'php'); INSERT INTO `config` VALUES ('xs_shownav', '1'); INSERT INTO `config` VALUES ('xs_template_time', '1124774689'); INSERT INTO `config` VALUES ('xs_use_cache', '1'); INSERT INTO `config` VALUES ('xs_version', '5'); INSERT INTO `config` VALUES ('xs_warn_includes', '1'); -- -------------------------------------------------------- PHP:
Via your PhpMyAdmin, go to the database, and config table which you created. Click on the "SQL" tab on the top.. and paste this code into the text field. Then click OK and you're done so far.