Help with code

Alofoxx

Member
Im trying to extend XenForo_DataWriter_User::_verifyUsername

So that when they signup on my site it checks the username against minecraft.net premium acct list.

its not working but here is what i did at the end of the function.
the goal is to add the username to the end of "http://www.minecraft.net/haspaid.jsp?user=" if its a paid acct it will return True otherwise it will be false. My name is alofoxx so it would send out http://www.minecraft.net/haspaid.jsp?user=alofoxx and returns true where as "fakename" "http://www.minecraft.net/haspaid.jsp?user=fakename" would return false and throw an error.
hope fully someone can tell me my errors in code :)

THANKS

PHP:
        // compare against romanized name to help reduce confusable issues
        $romanized = utf8_deaccent(utf8_romanize($username));
        if ($romanized != $username)
        {
            $existingUser = $this->_getUserModel()->getUserByName($romanized);
            if ($existingUser && $existingUser['user_id'] != $this->get('user_id'))
            {
                $this->error(new XenForo_Phrase('usernames_must_be_unique'), 'username');
                return false;
            }
        }
 
              //Alo minecraft verification
              /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
              try
              {             
                    if( strpos( $sRes, 'true' )=== FALSE );
                    {
                          $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                          return false;
                    }
              }
              catch (Exception $e) {}
              //End alo code
 
        return true;
 
if( strpos( $sRes, 'true' )=== FALSE );
{
$this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
return false;
}

Remove the semicolon immediately after the if.
 
http://www.minecraft.net/haspaid.jsp?user=fakeFucjasd
returns false.

http://fsrminecraft.com/index.php?login/login
enter the same name here and it does not show a error.

PHP:
        }
 
              //Alo minecraft verification
              /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
              try
              {             
                    if( strpos( $sRes, 'true' )=== FALSE )
                    {
                          $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                          return false;
                    }
              }
              catch (Exception $e) {}
             
              //End alo code
 
        return true;
 
oh crud. i left it out... herpderp its :

PHP:
  $sRes= file_get_contents( 'http://www.minecraft.net/haspaid.jsp?user='. rawurlencode( $data['username'] ) );

not sure where it goes in relation to "try"
i assumed the whole "try" catch would allow this not to be ignored if the minecraft.net is down
so would the correct code snip be then:

PHP:
        }
 
              //Alo minecraft verification
              /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
                $sRes= file_get_contents( 'http://www.minecraft.net/haspaid.jsp?user='. rawurlencode($username) );
              try
              {             
                    if( strpos( $sRes, 'true' )=== FALSE );
                    {
                          $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                          return false;
                    }
              }
              catch (Exception $e) {}
              //End alo code
 
        return true;
 
got
Parse error: syntax error, unexpected T_VARIABLE, expecting '{' in*****/library/XenForo/DataWriter/User.php on line 554
with
PHP:
              //Alo minecraft verification
              /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
              try
              $sRes= file_get_contents( 'http://www.minecraft.net/haspaid.jsp?user='. rawurlencode($username) );
              {           
                    if( strpos( $sRes, 'true' )=== FALSE )
                    {
                          $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                          return false;
                    }
              }
              catch (Exception $e) {}
           
              //End alo code
 
        return true;
 
code is based off of:
PHP:
            $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
 
 
 
            /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
            $sRes= file_get_contents( 'http://www.minecraft.net/haspaid.jsp?user='. rawurlencode( $user-> data['username'] ) );
            if( strpos( $aRes, 'true' )=== FALSE ) $error[]= 'The username must exist on Minecraft';
            /*** 2012-01-07 END ***/

source: https://www.phpbb.com/community/viewtopic.php?f=72&t=2139921
 
FSR Minecraft - Error
A server error occurred. Please try again later.
is what i get with a valid and non valid acct name.
PHP:
        }
 
              //Alo minecraft verification
              /*** 2012-01-07 BEGIN AmigoJack
                Check username: has Minecraft nick paid? ***/
 
              $sRes= file_get_contents( 'http://www.minecraft.net/haspaid.jsp?user='. rawurlencode($username) );
              {             
                    if( strpos( $sRes, 'true' )=== FALSE )
                    {
                          $this->error(new XenForo_Phrase('The_username_must_exist_on_Minecraft'), 'username');
                          return false;
                    }
              }
 
             
              //End alo code
 
        return true;
 
Error Info
ErrorException: file_get_contents() [<a href='function.file-get-contents'>function.file-get-contents</a>]: URL file-access is disabled in the server configuration - library/XenForo/DataWriter/User.php:554
Generated By: Unknown Account, Today at 5:34 AM
Stack Trace
#0 [internal function]: XenForo_Application::handlePhpError('http://www.mine...')
#1 ***/library/XenForo/DataWriter/User.php(554): file_get_contents('statachi', Object(WidgetFramework_Extend_DataWriter_User), 'username', Array)
#2 [internal function]: XenForo_DataWriter_User->_verifyUsername(Array, Array)
#3 ***/library/XenForo/DataWriter.php(965): call_user_func_array(Array, 'statachi', Array, 'username')
#4 ***/library/XenForo/DataWriter.php(720): XenForo_DataWriter->_runVerificationCallback('username', Array, 'statachi', Array)
#5 ***/library/XenForo/DataWriter.php(638): XenForo_DataWriter->_isFieldValueValid('username', 'statachi')
#6 ***/library/XenForo/ControllerPublic/Register.php(63): XenForo_DataWriter->set()
#7 ***/library/XenForo/FrontController.php(310): XenForo_ControllerPublic_Register->actionIndex(Object(XenForo_RouteMatch))
#8 ***/library/XenForo/FrontController.php(132): XenForo_FrontController->dispatch()
#9 ***/index.php(13): XenForo_FrontController->run()
#10 {main}
Request State
array(3) {
["url"] => string(45) "http://fsrminecraft.com/index.php?login/login"
["_GET"] => array(1) {
["login/login"] => string(0) ""
}
["_POST"] => array(5) {
["login"] => string(8) "statachi"
["register"] => string(1) "1"
["cookie_check"] => string(1) "1"
["redirect"] => string(33) "http://fsrminecraft.com/index.php"
["_xfToken"] => string(0) ""
}
}
 
Make sure allow_url_fopen is enabled in your PHP configuration. You can check this in your phpinfo by visiting:

admin.php?tools/phpinfo
 
Back
Top Bottom