How to execute php code (with zend api) without open file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Service4PC

    How to execute php code (with zend api) without open file

    Hi all,
    I've a problem... I'm writing an extension for php, and i need to
    execute a file php... but only the content of the file and not the
    file...
    Now I better explain:
    - the extension get the file content of a php file (php code and html
    code mixed..)
    - execute the content with some zend api function

    I've already tried with zend_eval_strin g but not good because not
    execute the html code/open php tag.
    The same for zend_execute_sc ript :(

    If someone has used the zend api, i need your help

    PS: sorry for my english, it is difficult to explain my goals :(
  • Erwin Moller

    #2
    Re: How to execute php code (with zend api) without open file

    Service4PC schreef:
    Hi all,
    I've a problem... I'm writing an extension for php, and i need to
    execute a file php... but only the content of the file and not the
    file...
    Now I better explain:
    - the extension get the file content of a php file (php code and html
    code mixed..)
    - execute the content with some zend api function
    >
    I've already tried with zend_eval_strin g but not good because not
    execute the html code/open php tag.
    The same for zend_execute_sc ript :(
    >
    If someone has used the zend api, i need your help
    >
    PS: sorry for my english, it is difficult to explain my goals :(
    Hi,

    Maybe I understand wrong, but if you need the raw PHP file, simply use
    the fylesystem functions to do so, and NO URL wrapper.

    for example:
    GOOD:
    // This will get the content of your PHP file
    $Path = "/home/service42/public_html/myPHPfile.php";
    $PHPContent = file_get_conten ts ($Path);

    BAD:
    // This will give you the result of the 'executed' file
    $URL = "http://www.example.com/~service42/myPHPfile.php";
    $PHPContent = file_get_conten ts ($URL);

    Regards,
    Erwin Moller


    Read more here:
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    --
    "There are two ways of constructing a software design: One way is to
    make it so simple that there are obviously no deficiencies, and the
    other way is to make it so complicated that there are no obvious
    deficiencies. The first method is far more difficult."
    -- C.A.R. Hoare

    Comment

    • Service4PC

      #3
      Re: How to execute php code (with zend api) without open file

      An example maybe clarify the ideas...

      file php:
      <?php
      myfunction('<pr e><?php echo "hello world"; ?></pre>'); // this cannot
      be execute with a simply eval :(
      ?>

      file extension.c
      [...]
      PHP_FUNCTION(my function)
      {
      char *code;
      int code_len;

      if (zend_parse_par ameters(ZEND_NU M_ARGS() TSRMLS_CC, "s", &code,
      &code_len) == FAILURE) {
      RETURN_NULL();
      }

      // how i can execute the source code of variable code????
      // ...
      }
      [...]

      i hope this help to explain my idea...

      On 18 Nov, 13:04, Erwin Moller
      <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
      Service4PC schreef:
      >
      >
      >
      Hi all,
      I've a problem... I'm writing an extension for php, and i need to
      execute a file php... but only the content of the file and not the
      file...
      Now I better explain:
       - the extension get the file content of a php file (php code and html
      code mixed..)
       - execute the content with some zend api function
      >
      I've already tried with zend_eval_strin g but not good because not
      execute the html code/open php tag.
      The        same for zend_execute_sc ript :(
      >
      If someone has used the zend api, i need your help
      >
      PS: sorry for my english, it is difficult to explain my goals :(
      >
      Hi,
      >
      Maybe I understand wrong, but if you need the raw PHP file, simply use
      the fylesystem functions to do so, and NO URL wrapper.
      >
      for example:
      GOOD:
      // This will get the content of your PHP file
      $Path = "/home/service42/public_html/myPHPfile.php";
      $PHPContent = file_get_conten ts ($Path);
      >
      BAD:
      // This will give you the result of the 'executed' file
      $URL = "http://www.example.com/~service42/myPHPfile.php";
      $PHPContent = file_get_conten ts ($URL);
      >
      Regards,
      Erwin Moller
      >
      Read more here:http://nl3.php.net/manual/en/ref.filesystem.php
      >
      --
      "There are two ways of constructing a software design: One way is to
      make it so simple that there are obviously no deficiencies, and the
      other way is to make it so complicated that there are no obvious
      deficiencies. The first method is far more difficult."
      -- C.A.R. Hoare

      Comment

      • Erwin Moller

        #4
        Re: How to execute php code (with zend api) without open file

        >
        On 18 Nov, 13:04, Erwin Moller
        <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
        >Service4PC schreef:
        >>
        >>
        >>
        >>Hi all,
        >>I've a problem... I'm writing an extension for php, and i need to
        >>execute a file php... but only the content of the file and not the
        >>file...
        >>Now I better explain:
        >> - the extension get the file content of a php file (php code and html
        >>code mixed..)
        >> - execute the content with some zend api function
        >>I've already tried with zend_eval_strin g but not good because not
        >>execute the html code/open php tag.
        >>The same for zend_execute_sc ript :(
        >>If someone has used the zend api, i need your help
        >>PS: sorry for my english, it is difficult to explain my goals :(
        >Hi,
        >>
        >Maybe I understand wrong, but if you need the raw PHP file, simply use
        >the fylesystem functions to do so, and NO URL wrapper.
        >>
        >for example:
        >GOOD:
        >// This will get the content of your PHP file
        >$Path = "/home/service42/public_html/myPHPfile.php";
        >$PHPContent = file_get_conten ts ($Path);
        >>
        >BAD:
        >// This will give you the result of the 'executed' file
        >$URL = "http://www.example.com/~service42/myPHPfile.php";
        >$PHPContent = file_get_conten ts ($URL);
        >>
        >Regards,
        >Erwin Moller
        >>
        >Read more here:http://nl3.php.net/manual/en/ref.filesystem.php
        >>

        Service4PC schreef:
        An example maybe clarify the ideas...
        >
        file php:
        <?php
        myfunction('<pr e><?php echo "hello world"; ?></pre>'); // this cannot
        be execute with a simply eval :(
        ?>
        >
        file extension.c
        [...]
        PHP_FUNCTION(my function)
        {
        char *code;
        int code_len;
        >
        if (zend_parse_par ameters(ZEND_NU M_ARGS() TSRMLS_CC, "s", &code,
        &code_len) == FAILURE) {
        RETURN_NULL();
        }
        >
        // how i can execute the source code of variable code????
        // ...
        }
        [...]
        >
        i hope this help to explain my idea...
        Hi,

        [Please don't toppost, fixed]

        I am still a bit at a loss.
        You php file was this:
        <?php
        myfunction('<pr e><?php echo "hello world"; ?></pre>');
        ?>

        What do you expect from that file?
        I mean: You can get its content via normal filesystemfunct ions as I
        described in my earlier post.

        What really is strange is of course the content itsef:
        myfunction('<pr e><?php echo "hello world"; ?></pre>');

        That is NOT executed PHP code: The "hello world" is not echo'ed at all.
        It is just the literal string '<pre><?php echo "hello world"; ?></pre>'
        being passed to some function.

        I don't know how your application is set up or supposed to do, but this
        looks like strange design to at first sight.
        I might be missing something though...

        Are you maybe writing some parser that will produce PHP sourcefiles itself?
        (Then it would make sense.)

        So sorry, it is still not clear to me. :-/

        Regards,
        Erwin Moller

        --
        "There are two ways of constructing a software design: One way is to
        make it so simple that there are obviously no deficiencies, and the
        other way is to make it so complicated that there are no obvious
        deficiencies. The first method is far more difficult."
        -- C.A.R. Hoare

        Comment

        • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

          #5
          Re: How to execute php code (with zend api) without open file

          Erwin Moller escribió:
          I might be missing something though...
          >
          Are you maybe writing some parser that will produce PHP sourcefiles itself?
          (Then it would make sense.)
          >
          So sorry, it is still not clear to me. :-/
          The OP is not writing PHP code. He's writing C code: a PHP extension to
          add new functions to PHP.


          --
          -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          -- Mi sitio sobre programación web: http://bits.demogracia.com
          -- Mi web de humor al baño María: http://www.demogracia.com
          --

          Comment

          • Erwin Moller

            #6
            Re: How to execute php code (with zend api) without open file

            Álvaro G. Vicario schreef:
            Erwin Moller escribió:
            >I might be missing something though...
            >>
            >Are you maybe writing some parser that will produce PHP sourcefiles
            >itself?
            >(Then it would make sense.)
            >>
            >So sorry, it is still not clear to me. :-/
            >
            The OP is not writing PHP code. He's writing C code: a PHP extension to
            add new functions to PHP.
            Hi,

            I understand that, but how does that explain this file he is working on
            and posted as a troublesome example?

            file php:
            <?php
            myfunction('<pr e><?php echo "hello world"; ?></pre>');
            ?>

            That is no C.
            It looks to me like a PHPsourcebuilde r application.

            But maybe we better let Service4PC comment on it, since I am only
            guessing here. I don't write PHP extensions myself.

            Regards,
            Erwin Moller


            --
            "There are two ways of constructing a software design: One way is to
            make it so simple that there are obviously no deficiencies, and the
            other way is to make it so complicated that there are no obvious
            deficiencies. The first method is far more difficult."
            -- C.A.R. Hoare

            Comment

            • Service4PC

              #7
              Re: How to execute php code (with zend api) without open file

              I don't need to write any line of php code, i want to write a php
              extension in c, the file php that i've posted is an example of the use
              of my "function".
              The php source content of the file for me is useless, because it will
              passed to function without fopen (i've already the content, for this i
              need this behavior).
              This example:
              <?php
              myfunction('<pr e><?php echo "hello world"; ?></pre>');
              ?>
              is only the final result of creation of my extension, extending the
              set of php functions with some "custom", the example just wanted to
              clarify how the ideas will be used later.

              The behavior should be as follows:
              - The parameter (block of php code) is passed to my function
              - The function internally prepare (in some way that I do not know)
              the parameter
              - Run (eg. eval) the code block

              On Nov 18, 7:06 pm, Erwin Moller
              <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
              Álvaro G. Vicario schreef:
              >
              Erwin Moller escribió:
              I might be missing something though...
              >
              Are you maybe writing some parser that will produce PHP sourcefiles
              itself?
              (Then it would make sense.)
              >
              So sorry, it is still not clear to me. :-/
              >
              The OP is not writing PHP code. He's writing C code: a PHP extension to
              add new functions to PHP.
              >
              Hi,
              >
              I understand that, but how does that explain this file he is working on
              and posted as a troublesome example?
              >
              file php:
              <?php
              myfunction('<pr e><?php echo "hello world"; ?></pre>');
              ?>
              >
              That is no C.
              It looks to me like a PHPsourcebuilde r application.
              >
              But maybe we better let Service4PC comment on it, since I am only
              guessing here. I don't write PHP extensions myself.
              >
              Regards,
              Erwin Moller
              >
              --
              "There are two ways of constructing a software design: One way is to
              make it so simple that there are obviously no deficiencies, and the
              other way is to make it so complicated that there are no obvious
              deficiencies. The first method is far more difficult."
              -- C.A.R. Hoare

              Comment

              • Curtis

                #8
                Re: How to execute php code (with zend api) without open file

                On Tue, 18 Nov 2008 00:56:21 -0800 (PST), service4pc@gmai l.com wrote:
                Hi all,
                I've a problem... I'm writing an extension for php, and i need to
                execute a file php... but only the content of the file and not the
                file...
                Now I better explain:
                - the extension get the file content of a php file (php code and html
                code mixed..)
                - execute the content with some zend api function
                So, what is your overall goal? What, exactly, does your extension
                do? It may be possible an extension doing what you want exists in
                the PECL repository. It might also be possible what you're
                attempting can be done natively in PHP.
                I've already tried with zend_eval_strin g but not good because not
                execute the html code/open php tag.
                The same for zend_execute_sc ript :(
                >
                If someone has used the zend api, i need your help
                Perhaps I'm too ignorant of PHP extension authoring, but I wasn't
                able to turn up much documentation on the Zend API through web
                searches. One of the best resources I did find was php.net's
                documentation and the user notes.

                <URL:http://php.net/manual/en/internals2.ze1. zendapi.php>
                PS: sorry for my english, it is difficult to explain my goals :(
                That's nothing to apologize for.

                --
                Curtis
                $email = str_replace('si g.invalid', 'gmail.com', $from);

                Comment

                Working...