php+mysql-driven webpage

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

    php+mysql-driven webpage

    Hi!

    I have a little problem:

    I have php-code stored in a mysql-table.
    How do i run this code?

    if i echo it, i see the code, but how do i run it?

    thx,
    Michael


  • Pedro Graca

    #2
    Re: php+mysql-driven webpage

    Michael Volk wrote:[color=blue]
    > I have php-code stored in a mysql-table.
    > How do i run this code?
    >
    > if i echo it, i see the code, but how do i run it?[/color]

    eval() it.


    --
    --= my mail address only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10K =--

    Comment

    • Ian.H

      #3
      Re: php+mysql-driven webpage

      On Fri, 28 Nov 2003 11:28:39 +0100, Michael Volk wrote:
      [color=blue]
      > Hi!
      >
      > I have a little problem:
      >
      > I have php-code stored in a mysql-table. How do i run this code?
      >
      > if i echo it, i see the code, but how do i run it?
      >
      > thx,
      > Michael[/color]


      eval()

      </whince>


      I strongly believe though, if 'eval()' is the answer, you're asking the
      wrong question =)



      Regards,

      Ian

      --
      Ian.H [Design & Development]
      digiServ Network - Web solutions
      www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
      Programming, Web design, development & hosting.

      Comment

      • Michael Volk

        #4
        Re: php+mysql-driven webpage

        hi!
        thx for that...

        there is not only php-code in this field, but theres also html.
        is eval() working for that to?

        its a complete site with html AND php-code stored.

        thx,
        Michael


        "Pedro Graca" <hexkid@hotpop. com> schrieb im Newsbeitrag
        news:bq78lk$1vf e93$1@ID-203069.news.uni-berlin.de...[color=blue]
        > Michael Volk wrote:[color=green]
        > > I have php-code stored in a mysql-table.
        > > How do i run this code?
        > >
        > > if i echo it, i see the code, but how do i run it?[/color]
        >
        > eval() it.
        >
        > http://www.php.net/eval
        > --
        > --= my mail address only accepts =--
        > --= Content-Type: text/plain =--
        > --= Size below 10K =--[/color]


        Comment

        • Kevin Thorpe

          #5
          Re: php+mysql-driven webpage

          Michael Volk wrote:[color=blue]
          > hi!
          > thx for that...
          >
          > there is not only php-code in this field, but theres also html.
          > is eval() working for that to?[/color]

          IIRC eval starts in <?php context so if you have a complete webpage
          including code then do:
          eval("?>$page<? php");

          Comment

          • Pedro Graca

            #6
            Re: php+mysql-driven webpage

            Kevin Thorpe wrote:[color=blue]
            > IIRC eval starts in <?php context so if you have a complete webpage
            > including code then do:
            > eval("?>$page<? php");[/color]

            I couldn't get eval to work with my example :(

            So I made a function to eval my example :)

            Hope it can help the OP

            =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
            <code language="php" length="41 lines">
            <?php
            $db_value = '<b><?php echo phpversion(); ?></b>
            foobar
            <?php $x=date("Y-m-d"); ?>
            foobaz
            <?php echo $x; ?>
            foobar again';

            echo code_eval($db_v alue);
            echo "\n--------\n";
            eval("?>$db_val ue<?php"); ## error here!

            function code_eval($__ST O_string) {
            ## __STO_ (security through obscurity)

            // isolate all code between the php tags
            preg_match_all( '/<\?php(.*)\?>/Us', $__STO_string, $__STO_php_code );

            // eval each one of them and store each evaluation in an array
            $__STO_evaled = array();
            foreach ($__STO_php_cod e[1] as $__STO_sub_code ) {
            ob_start();
            eval($__STO_sub _code);
            $__STO_evaled[] = ob_get_clean();
            }

            // replace code and php tags by their result
            $__STO_i = 0;
            $__STO_string_e valed = $__STO_string;
            while (isset($__STO_e valed[$__STO_i])) {
            $__STO_string_e valed = preg_replace('/<\?php(.*)\?>/Us',
            $__STO_evaled[$__STO_i],
            $__STO_string_e valed,
            1);
            ++$__STO_i;
            }

            // return the eval'd chunk
            return $__STO_string_e valed;
            }
            ?>
            </code>
            --
            --= my mail address only accepts =--
            --= Content-Type: text/plain =--
            --= Size below 10K =--

            Comment

            • Chung Leong

              #7
              Re: php+mysql-driven webpage

              Another way to do this is through remote include(). Use an URL in
              place of a file path like this:

              include("http://localhost/db_php_code.php ?criteria=somet hing");

              In db_php_code.php , connect to the database and echo the code.

              "Michael Volk" <micha_volk@t-online.de> wrote in message news:<bq78pn$le q$04$1@news.t-online.com>...[color=blue]
              > hi!
              > thx for that...
              >
              > there is not only php-code in this field, but theres also html.
              > is eval() working for that to?
              >
              > its a complete site with html AND php-code stored.
              >
              > thx,
              > Michael
              >
              >
              > "Pedro Graca" <hexkid@hotpop. com> schrieb im Newsbeitrag
              > news:bq78lk$1vf e93$1@ID-203069.news.uni-berlin.de...[color=green]
              > > Michael Volk wrote:[color=darkred]
              > > > I have php-code stored in a mysql-table.
              > > > How do i run this code?
              > > >
              > > > if i echo it, i see the code, but how do i run it?[/color]
              > >
              > > eval() it.
              > >
              > > http://www.php.net/eval
              > > --
              > > --= my mail address only accepts =--
              > > --= Content-Type: text/plain =--
              > > --= Size below 10K =--[/color][/color]

              Comment

              Working...