1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Execute PHP Script on Website

Discussion in 'Skript' started by xXSwainXx, Sep 27, 2020.

Thread Status:
Not open for further replies.
  1. xXSwainXx

    xXSwainXx Active Member

    Joined:
    Jan 27, 2017
    Messages:
    55
    Likes Received:
    5
    Hey,

    I have a PHP file for creating a User on my Website:

    Code (Text):
    1. <?php
    2. //UserAgent abfrage damit nicht jeder neue accounts erstellen kann.
    3. if(($_SERVER['HTTP_USER_AGENT'] == "MeinUserAgent/s8HLVxQIDC") === false){
    4.     //Fals Useragent falsch sein sollte gibt es ein 'Invalid Page' zur�ck und l�st die Page auslaufen
    5.     echo('NÖ');die;
    6. }
    7.  
    8. $username = "";
    9. $email = "";
    10. $password = "";
    11. $uuid = "";
    12. $isVerified = "1";
    13. $mcName = $username;
    14. $rang = "";
    15.  
    16. //Hier werden die �bergebenen POST variablen ausgelesen und in die lokalen variablen geschrieben diesen schritt k�nnte man
    17. //sich sparen mit $_POST['username']
    18. foreach ($_POST as $key => $value) {
    19.     switch ($key) {
    20.         case 'username':$username = $value;break;
    21.         case 'email':$email = $value;break;
    22.         case 'password':$password = $value;break;
    23.         case 'uuid':$uuid = $value;break;
    24.         case 'isVerified':$uuid = $value;break;
    25.         case 'mcName':$mcName = $value;break;
    26.         default:break;
    27.     }
    28. }
    29.  
    30. //Eine IF abfrage ob die Lokalen Variablen gesetzt sind
    31. if($username!="" and $email!="" and $password!="" and $uuid!="" and $isVerified!="" and $mcName!=""){
    32.     //LINK = link zur global.php welche normalerweise im Hauptverzeichnis des WSC liegt
    33.     if (!defined('RELATIVE_WBB_DIR')) define('RELATIVE_WBB_DIR', 'LINK');
    34.     require('global.php');
    35.     //Hier wird der data[] geschrieben in den wir Username/Password/Email hinterlegen
    36.     $data = array('username' => $username,'password' => $password,'email' => $email, 'isVerified' => $isVerified, 'mcName' => $mcName, 'uuid' => $uuid);
    37.     //array_map('trim', array) wird hier �fters benutzt hierbei handelt es sich um eine Funktion welche white_space im array zu l�schen damit keine
    38.     //falschen daten benutzt werden
    39.     $data = array_map('trim', $data);
    40.  
    41.     //Nun wird es etwas tricky wir wollen ja �berpr�fen ob die Daten Valid sind.
    42.     //Wir greifen hierzu auf verschiedene Funktionen relativ zu.
    43.     // \wcf\util\UserRegistrationUtil leigt hierbei in /forum/wcf/lib/util/UserRegistrationUtil
    44.     //
    45.     //isValidUsername �berpr�ft den Username/Password/Email auf die eingestellten optionen
    46.     //getUserByUsername �berpr�ft ob Nutzer bereits existiert
    47.     //isValidEmail �berpr�ft die �bertragene Email adresse auf richtigkeit
    48.     //getUserByEmail �berpr�ft ob Email bereits existiert
    49.     $valid = \wcf\util\UserRegistrationUtil::isValidUsername($data['username']);
    50.     $userBool = \wcf\data\user\User::getUserByUsername($data['username']);
    51.     $validEmail = \wcf\util\UserRegistrationUtil::isValidEmail($data['email']);
    52.     $emailBoold = \wcf\data\user\User::getUserByEmail($data['email']);
    53.  
    54.     //Hier kommen nun die IF abfragen welche das Script beenden fals z.B ein Username bereits registriert ist
    55.     //Die zur�ckgegeben echo sind frei erfunden
    56.     if(!$valid){echo("USERNAME_INVALID");die;}
    57.     if($userBool->getUserID()!=0){echo("USERNAME_ALREADY_EXIST");die;}
    58.     if(!$validEmail){echo("EMAIL_INVALID");die;}
    59.     if($emailBoold->getUserID()!=0){echo("EMAIL_ALREADY_EXIST");die;}
    60.  
    61.     //Hier wird ein String in ein Benutzerdefiniertes Feld geschrieben kann man auch weglassen
    62.     $userAction = new \wcf\data\user\UserAction(array(), 'create', array(
    63.             'data' => $data
    64.     ));
    65.    
    66.     //Eintragung ohne Profilfeld
    67.     //$userAction = new \wcf\data\user\UserAction(array(), 'create', array('data' => $data));
    68.    
    69.     //Die UserAction wird hier ausgef�hrt
    70.     $returnValues = $userAction->executeAction();
    71.    
    72.     //$returnValues['returnValues'] gibt uns ein User Obj zur�ck wcf\lib\data\user\User
    73.     $user = $returnValues['returnValues'];
    74.    
    75.     //Hier �bertragen wir die UserID zur�ck um sie in Java zu benutzen
    76.     echo ("ERFOLGREICH_REGISTRIERT:" . $user->getUserID());
    77.  
    78.     //Nun k�nnen wir noch die Gruppen f�r unseren neuen User bearbeiten
    79.     $userAction = new \wcf\data\user\UserAction(array($user), 'addToGroups', array(
    80.                 //Gruppe 12 ist bei mir die Spieler gruppe einzusehen sind die ID's im acp unter der Benutzergruppen
    81.                 'groups' => [3],
    82.                 //Ich m�chte die Standartgruppen nicht l�schen
    83.                 'deleteOldGroups' => false,
    84.                 //�ber diesen Schritt kann man sich streiten ob dieser n�tig ist da beim erstellen eines User die DefaultGroups
    85.                 //bereits gesetzt sind
    86.                 'addDefaultGroups' => true
    87.             ));
    88.     //Action wird nun ausgef�hrt
    89.     $userAction->executeAction();
    90.    
    91.     //Nun k�nnen wir noch ein Profilbild setzen dies Mach ich damit ich meinen Benutzer die Minecraft Avatare zu setzen
    92.     $userAvatarAction = new \wcf\data\user\avatar\UserAvatarAction(array($user->getUserID()), 'fetchRemoteAvatar', array(
    93.                 'url' => "https://visage.surgeplay.com/head/128/".$uuidArray['uuid'],
    94.                 'userEditor' => new \wcf\data\user\UserEditor($user)
    95.             ));
    96.             $userAvatarAction->executeAction();
    97.     \wcf\system\user\storage\UserStorageHandler::getInstance()->reset(array($user->getUserID()), 'avatar');
    98. }else{
    99.     echo('Angaben sind leer!');
    100. }
    101. ?>
    So i have also a java code:

    Code (Text):
    1.     public void register(final String username, UUID uuid,final String email,final String password){
    2.         new Thread(new Runnable() {
    3.             @Override
    4.             public void run() {
    5.                 try{
    6.                     //URL zur unseren selbst geschriebenen php Datei
    7.                     URL url = new URL("LINK");
    8.                    
    9.                     //Hier wird die Connection hergestellt und unser User-Agent eingestellt
    10.                     URLConnection connection = (URLConnection) url.openConnection();
    11.                     connection.setRequestProperty("User-Agent", "MeinUserAgent/s8HLVxQIDC");
    12.                     //Wir wollen den Script eine anfrage senden also muss setDoOutput auf true stehen natürlich
    13.                     //wollen wir eine Rückmeldung bekommen also setDoInput auch auf true damit können wir über
    14.                     //php via echo() eine Rückmeldung geben
    15.                     connection.setDoOutput(true);
    16.                     connection.setDoInput(true);
    17.                    
    18.                     PrintStream stream = new PrintStream(connection.getOutputStream());
    19.                    
    20.                     //Hier werden die Felder gesetzt
    21.                     stream.println("username=" + username);
    22.                     stream.println("&email=" + email);
    23.                     stream.println("&password=" + password);
    24.                     stream.println("&uuid=" + uuid.toString());
    25.                    
    26.                     //Hier wird der Stream ausgeführt
    27.                     BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    28.                     stream.checkError();
    29.                     stream.flush();
    30.                     stream.close();
    31.                    
    32.                     String line = null;
    33.                    
    34.                     //Durchlaufen des echo()
    35.                     while ((line = reader.readLine()) != null) {
    36.                         if(line.startsWith("USER_REGSITER_SUCCESS")){
    37.                             if(userName.containsKey(p.getUniqueId())) userName.remove(p.getUniqueId());
    38.                             System.out.println("Du hast dich erfolgreich registriert.");
    39.                             System.out.println("Benutzername: §2" + p.getName());
    40.                             System.out.println("Email Adresse: §2" + email);
    41.                             System.out.println("Passwort: §2" + password);
    42.                         }else if(line.equalsIgnoreCase("USERNAME_INVALID_EXCEPTION")){
    43.                             System.out.println("Dein Spielername ist ungültig.");
    44.                         }else if(line.equalsIgnoreCase("USERNAME_ALREADY_EXCEPTION")){
    45.                             System.out.println("Du hast dich bereits registriert.");
    46.                         }else if(line.equalsIgnoreCase("EMAIL_INVALID_EXCEPTION")){
    47.                             System.out.println("Dine Email adresse enspricht nicht den vorgaben.");
    48.                         }else if(line.equalsIgnoreCase("EMAIL_ALREADY_EXCEPTION")){
    49.                             System.out.println("Deine Email Adresse ist bereits vergeben.");
    50.                         }
    51.                     }
    52.                 }catch(Exception ex){
    53.                     ex.printStackTrace();
    54.                 }
    55.             }
    56.         }).start();
    57.     }
    Can i also make a Skript?? becouse i can't work with java :emoji_grinning: is it possible to make this in skript also?
     
  2. Linegrite

    Linegrite Member

    Joined:
    May 22, 2020
    Messages:
    17
    Likes Received:
    3
    Try this
    Code (Text):
    1. send a request to "Your request"
     
  3. xXSwainXx

    xXSwainXx Active Member

    Joined:
    Jan 27, 2017
    Messages:
    55
    Likes Received:
    5
    But how i can fill in the Minecraftname, UUID, Email and PW??
     
  4. Linegrite

    Linegrite Member

    Joined:
    May 22, 2020
    Messages:
    17
    Likes Received:
    3
    Create a request, like "mysite.com/newuser.php?user={user}&password={pass}"
     
  5. xXSwainXx

    xXSwainXx Active Member

    Joined:
    Jan 27, 2017
    Messages:
    55
    Likes Received:
    5
    I will try :emoji_grinning:
    --- Double Post Merged, Oct 1, 2020, Original Post Date: Sep 29, 2020 ---
    How i can ask if the user exist??
    --- Double Post Merged, Oct 1, 2020 ---
    Becouse when i execute my command

    Code (Text):
    1. command /forum [<text>] [<text>]:
    2.     description: Registrierung für das Forum SkyVenix
    3.     aliases: reg
    4.     trigger:
    5.         if arg-1 is not set:
    6.             message "&7Forum &1> &cNutze Bitte /forum <email> <passwort>"
    7.             stop
    8.         else if arg-2 is not set:
    9.             message "&7Forum &1> &cNutze Bitte /forum <email> <passwort>"
    10.         else if arg-2 is set:
    11.             message "&7Forum &1> &aEin Foren Account wird für dich angelegt..."
    12.             send a request to "https://skyvenix.eu/mc-user-create.php?parameter1=%player%&parameter2=%UUID of player%&parameter3=%arg-1%&parameter4=%arg-2%"
    13.             message "https://skyvenix.eu/mc-user-create.php?parameter1=%player%&parameter2=%UUID of player%&parameter3=%arg-1%&parameter4=%arg-2%"
    14.  
    There is nothing hepening but when i click on the link in the chat in minecraft it works :emoji_frowning: what i am making false? and in the console is also nothing...
     
  6. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,500
    Likes Received:
    107
    Medals:
    Have you looked at the http response? It'll probably have more information
     
  7. xXSwainXx

    xXSwainXx Active Member

    Joined:
    Jan 27, 2017
    Messages:
    55
    Likes Received:
    5
    What do you mean?
     
  8. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,500
    Likes Received:
    107
    Medals:
    Reqn has Last Response, which gives you a lot of info about the response (message / broadcast it)
     
  9. xXSwainXx

    xXSwainXx Active Member

    Joined:
    Jan 27, 2017
    Messages:
    55
    Likes Received:
    5
    @TPGamesNL but when i execute the command the server is not executing the link

    Code (Text):
    1. send a request to "https://skyvenix.eu/article/1-staff-anforderungen/"
    https://prnt.sc/urzkzy <-- the site has 0 views why
    --- Double Post Merged, Oct 3, 2020, Original Post Date: Oct 2, 2020 ---
    Hey Guys,

    The solution is now this Code:

    Code (Text):
    1. send a request to "https://skyvenix.eu/mc-user-create.php?parameter1=%player%&parameter2=%UUID of player%&parameter3=%arg-1%&parameter4=%arg-2%&parameter5=%{_userperm::%player%}%" with the headers "User-Agent: MeinUserAgent/s8HLVxQIDC"

    The Problem was that Cloudflare has blocked the request and than i have added the "User-Agent" and then it works :emoji_grinning:

    Thx for your help @TPGamesNL
     
    • Friendly Friendly x 1
Thread Status:
Not open for further replies.

Share This Page

Loading...