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

Solved How to run code using 'curl'?

Comments in 'Plugin Development' started by korado531m7, Dec 9, 2015.

  1. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Hi.
    I wanna run code using 'curl'.
    I wrote below, but couldn't run.
    Displayed codes in console directory.
    So didn't run code.
    How can i fix this?
    PHP:
    $curl curl_init("http://example.com/example.php");
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
    $response curl_exec($curl);
    $this->getLogger()->info($response);
    curl_close($curl);
    example.php written:
    $this->getLogger()->notice("now testing");
    $this->getLogger()->info("Testing");

    thank you for reading my thread, and answering.
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    this is the pocketmine forum and why do you need to run code from a website? anyway , you can try:

    PHP:
    $code=file_get_contents('http://ex.com/example.html');
    eval(
    $code);

    //file_get_contents() return a string 
    //eval() evaluate the php code 
    //http://php.net/manual/en/function.eval.php
    //for more info about eval use Google
    Last edited: Dec 9, 2015
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you!! Worked!!
    I forgot that..
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use Utils::getURL() and Utils::postURL() directly. They are in the class pocketmine\utils\Utils
    1. That would normally not work with HTTPS
    2. Never ever eval unverified code from external sources. In that way, if one day by some accidents the external source got hacked or the DNS got seized by someone else, you are exposing your whole system's vulnerability.
    A possible safer (but not safest) solution is to use a checksum to validate the code, but in that case, why don't you simply embed the code into the plugin?
    Andrey Nazarchuk and Legoboy0215 like this.
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    Thank you for advice.
    I'll use that.

Share This Page

Advertisement