glennn.php Posted September 7, 2008 Share Posted September 7, 2008 i have an htpassword.php file that works just fine on one godaddy server but i'm getting this parse error on another: parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/content/j/s/i/jsimkav/html/headers/htpasswd.php on line 33 can someone point out the problem for me? line 33: class htpasswd{ public $users; << 33 public $error; private $_path; function htpasswd($file=false){ if(!$file){ die('Please specify a file!'); }else{ //configure $this->_path = $file; $this->users = ''; //load database if(file_exists($file)){ $data = array(); $fcontents = file($file); while(list($line_num, $line) = each($fcontents)){ $user = explode(':',$line); //$user = $arraydata[0]; $data[$user[0]] = rtrim($user[1]); } $this->users = $data; } } } function create($user, $passwd, $update=false){ $this->error = ''; if(isset($this->users[$user]) && !$update){ $this->error = 'User <strong>'.$user.'</strong> exists! To update the user set the update parameter to true.'; return false; } $this->users[$user] = $this->non_salted_sha1($passwd); return true; } function remove($user){ $this->error = ''; if(isset($this->users[$user])){ unset($this->users[$user]); return true; }else{ $this->error = 'User <strong>'.$user.'</strong> does not exist!'; return false; } } function users(){ $this->error = ''; $rval = Array(); if(is_array($this->users)){ foreach(array_keys($this->users) as $uid){ $rval[count($rval)] = $uid; } } return $rval; } function validate($user, $pass){ $this->error = ''; if(!isset($this->users[$user])) return False; $crypted = $this->users[$user]; if(substr($crypted, 0, 6) == "{SSHA}"){ $ohash = base64_decode(substr($crypted, 6)); return substr($ohash, 0, 20) == pack("H*", sha1($pass . substr($ohash, 20))); }elseif(substr($crypted, 0, 5) == "{SHA}"){ return ($this->non_salted_sha1($pass) == $crypted); }else{ return ($pass == $crypted); } } function save($file=false){ $fcontents = ""; if($file == false) $file = $this->_path; foreach(array_keys($this->users) as $user){ $fcontents .= $user.":".$this->users[$user]."\n"; } if(file_put_contents($file, $fcontents)){ $this->error = ''; return true; }else{ $this->error = 'Couln\'t save the file!'; return false; } } //encryption functions function rand_salt_crypt($pass){ $salt = ""; mt_srand((double)microtime()*1000000); for ($i=0; $i<CRYPT_SALT_LENGTH; $i++) $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./", mt_rand() & 63, 1); return "$apr1$".crypt($pass, $salt); } function rand_salt_sha1($pass){ mt_srand((double)microtime()*1000000); $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); return "{SSHA}".base64_encode(pack("H*", sha1($pass . $salt)) . $salt); } function non_salted_sha1($pass){ return "{SHA}".base64_encode(pack("H*", sha1($pass))); } } //php4 work around if(!function_exists('file_put_contents')){ function file_put_contents($filename, $content, $flags = null, $resource_context = null){ if(is_array($content)){ $content = implode('', $content); } if(!is_scalar($content)){ trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING); return false; } $length = strlen($content); $mode = ($flags &FILE_APPEND) ? 'a' : 'w'; $use_inc_path = ($flags &FILE_USE_INCLUDE_PATH) ? true : false; if(($fh = @fopen($filename, $mode, $use_inc_path)) === false){ trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING); return false; } $bytes = 0; if(($bytes = @fwrite($fh, $content)) === false){ $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', $length, $filename); trigger_error($errormsg, E_USER_WARNING); return false; } @fclose($fh); if($bytes != $length){ $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', $bytes, $length); trigger_error($errormsg, E_USER_WARNING); return false; } return $bytes; } } ?> Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/ Share on other sites More sharing options...
ratcateme Posted September 7, 2008 Share Posted September 7, 2008 i don't know what versions this effects but i would suggest the second server is PHP4 and the way classes work between PHP4 and PHP5 is very different that could be causing your error. Scott. Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635619 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 yeah, that's what i thought at first, but the writer states that it's good on PHP 4 and up... godaddy is running 4.2 i think (at least). Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635620 Share on other sites More sharing options...
ratcateme Posted September 7, 2008 Share Posted September 7, 2008 have you checked that the php versions of both servers are the same or similar? Scott. Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635625 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 no, i haven't - i considered it, then went on to something else to see what someone like yourself tells me first. i can't imagine that they'd have different versions on different Linux servers, though. guess it's possible. i'll check that out. thanks Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635631 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 have you checked that the php versions of both servers are the same or similar? Scott. bingo damnit. one server is running 5.2 and one is running 4.3. i can't imagine why they'd do that, it's never been an option when i chose different host plans, just Linux of Windows... damn that pisses me off. the script still calls for 4 or better, but who knows... thanks for your prompt. g Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635638 Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 private, public, and protected object models weren't introduced until PHP5 Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635641 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 yeah, i sent the author an email asking why his website states 4 or better - he must have changed the script and not changed the notice on his site. that sure cost me a lot of time. ) thanks Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635644 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 private, public, and protected object models weren't introduced until PHP5 is there any way to change those class objects into something that would fly? perhaps you could point me in the right direction...? thanks Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635645 Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 No way to test this on my end, but try this: <?php class htpasswd{ var $users; var $error; var $_path; /* private */ function htpasswd($file=false){ if(!$file){ die('Please specify a file!'); }else{ //configure $this->_path = $file; $this->users = ''; //load database if(file_exists($file)){ $data = array(); $fcontents = file($file); while(list($line_num, $line) = each($fcontents)){ $user = explode(':',$line); //$user = $arraydata[0]; $data[$user[0]] = rtrim($user[1]); } $this->users = $data; } } } function create($user, $passwd, $update=false){ $this->error = ''; if(isset($this->users[$user]) && !$update){ $this->error = 'User <strong>'.$user.'</strong> exists! To update the user set the update parameter to true.'; return false; } $this->users[$user] = $this->non_salted_sha1($passwd); return true; } function remove($user){ $this->error = ''; if(isset($this->users[$user])){ unset($this->users[$user]); return true; }else{ $this->error = 'User <strong>'.$user.'</strong> does not exist!'; return false; } } function users(){ $this->error = ''; $rval = Array(); if(is_array($this->users)){ foreach(array_keys($this->users) as $uid){ $rval[count($rval)] = $uid; } } return $rval; } function validate($user, $pass){ $this->error = ''; if(!isset($this->users[$user])) return False; $crypted = $this->users[$user]; if(substr($crypted, 0, 6) == "{SSHA}"){ $ohash = base64_decode(substr($crypted, 6)); return substr($ohash, 0, 20) == pack("H*", sha1($pass . substr($ohash, 20))); }elseif(substr($crypted, 0, 5) == "{SHA}"){ return ($this->non_salted_sha1($pass) == $crypted); }else{ return ($pass == $crypted); } } function save($file=false){ $fcontents = ""; if($file == false) $file = $this->_path; foreach(array_keys($this->users) as $user){ $fcontents .= $user.":".$this->users[$user]."\n"; } if(file_put_contents($file, $fcontents)){ $this->error = ''; return true; }else{ $this->error = 'Couln\'t save the file!'; return false; } } //encryption functions function rand_salt_crypt($pass){ $salt = ""; mt_srand((double)microtime()*1000000); for ($i=0; $i<CRYPT_SALT_LENGTH; $i++) $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./", mt_rand() & 63, 1); return "$apr1$".crypt($pass, $salt); } function rand_salt_sha1($pass){ mt_srand((double)microtime()*1000000); $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); return "{SSHA}".base64_encode(pack("H*", sha1($pass . $salt)) . $salt); } function non_salted_sha1($pass){ return "{SHA}".base64_encode(pack("H*", sha1($pass))); } } //php4 work around if(!function_exists('file_put_contents')){ function file_put_contents($filename, $content, $flags = null, $resource_context = null){ if(is_array($content)){ $content = implode('', $content); } if(!is_scalar($content)){ trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING); return false; } $length = strlen($content); $mode = ($flags &FILE_APPEND) ? 'a' : 'w'; $use_inc_path = ($flags &FILE_USE_INCLUDE_PATH) ? true : false; if(($fh = @fopen($filename, $mode, $use_inc_path)) === false){ trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING); return false; } $bytes = 0; if(($bytes = @fwrite($fh, $content)) === false){ $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s', $length, $filename); trigger_error($errormsg, E_USER_WARNING); return false; } @fclose($fh); if($bytes != $length){ $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.', $bytes, $length); trigger_error($errormsg, E_USER_WARNING); return false; } return $bytes; } } ?> Edit* I didn't write this, I used the PHP5 to PHP4 convertor Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635646 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 thanks i will - can i ask what   is...? Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635651 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 awesome - that did the trick! thanks Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635653 Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 some form of htmlentity Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635654 Share on other sites More sharing options...
glennn.php Posted September 7, 2008 Author Share Posted September 7, 2008 i just turned them all into spaces and the file ran great... thanks again Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635656 Share on other sites More sharing options...
jonsjava Posted September 7, 2008 Share Posted September 7, 2008 would you be kind enough to mark this thread solved? Thanks! Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635657 Share on other sites More sharing options...
PFMaBiSmAd Posted September 7, 2008 Share Posted September 7, 2008 Support for php4 ended 9 months ago. Check with your host how to change the account still using php4 to php5. There will either be a control panel menu item or a setting in a .htaccess file. Link to comment https://forums.phpfreaks.com/topic/123080-solved-parse-error-htpasswordphp-works-fine-on-one-server-errors-on-another/#findComment-635718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.