TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-17-2007, 01:30 AM   #1 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default Having an issue with eval'd code

Well this is the file thats being parsed

PHP Code:
<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo(
'ello there');
}
</
phpcode

and this is the file that runs the code within <phpcode>

PHP Code:
        //runs the php within template files             
        
public function Runphp($txt)
        {    
            
//split it away from the rest of the text
            
$php preg_split("/(<phpcode>.*<\\/phpcode>)/Us"$txt, -1PREG_SPLIT_DELIM_CAPTURE);
            
$stop count($php);
            
            
//run the loop and execute the php
            
for($phpe 0$phpe $stop; ++$phpe)
            {
                
$phpexc $php[$phpe];
                if (
preg_match("/^<phpcode>(.*)<\\/phpcode>/Us"$phpexc$phpexec))
                {
                    
$phpex_p $phpexec[1];
                    
ob_start();
                    eval(
$phpex_p);
                    
$c =  ob_get_clean;
                    
$c str_replace('ob_get_clean','',$c);
                    
$c preg_replace('/(<phpcode>.*<\\/phpcode>)/Us',$c,$txt,$stop);
                    return 
$c//return it
                
}
            }
        } 

maybe I'm missing something plainly obvious but the hello link is supposed to be before the 'ello there' and it's being switched around, any help would be appreciated


(sorry if it's in the wrong section)
TlcAndres is offline  
Reply With Quote
Old 12-17-2007, 04:03 PM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

I kinda refixed the script, using PHP 5.2.5.
Execute.php;
PHP Code:
<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo 
'First off, why would you use echo ()? It\'s a function more simply used as echo "this";, not like you had.<br>';
    echo 
'next off, tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time.';
}
</
phpcode
File.php;
PHP Code:
<?php
        
        
//runs the php within template files             
        
function Runphp($txt)
        {    
            
//split it away from the rest of the text
            
$php preg_split("/(<phpcode>.*<\\/phpcode>)/Us"$txt, -1PREG_SPLIT_DELIM_CAPTURE);
            
$stop count($php);
            
            
//run the loop and execute the php
            
for($phpe 0$phpe $stop; ++$phpe)
            {
                
$phpexc $php[$phpe];
                if (
preg_match("/^<phpcode>(.*)<\\/phpcode>/Us"$phpexc$phpexec))
                {
                    
$phpex_p $phpexec[1];
                    
ob_start();
                    eval(
$phpex_p);
                    
$c =  ob_get_clean;
                    
$c str_replace('ob_get_clean','',$c);
                    
$c preg_replace('/(<phpcode>.*<\\/phpcode>)/Us',$c,$txt,$stop);
                    return 
$c//return it
                
}
            }
        }  

        
$file file_get_contents('execute.php');
        
        
Runphp($file);
        
?>
Exports:
PHP Code:
First offwhy would you use echo ()? It's a function more simply used as echo "this";, not like you had.
next off, tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time. 
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 12-17-2007, 04:09 PM   #3 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
tryping if (TRUE) { on one line, not on two, will shorten the length of your script thus the load time.
I would never give up usability for 0.000000000000000001 ms of faster loading time.

Hence:

Quote:
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 12-17-2007, 04:35 PM   #4 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Quote:
Originally Posted by Haris View Post
I would never give up usability for 0.000000000000000001 ms of faster loading time.

Hence:
Hey, don't shoot the messenger. I simply read it somewhere and I picked it up. Next to that, why would you create one extra line at each if, else or elseif line? I guess the same goes for while, for and foreach? Your scriptsize will get smaller which is better.

Getting back to the real topic subject, let me know if it works out.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 12-17-2007, 09:11 PM   #5 (permalink)
The Addict
 
Join Date: Nov 2007
Posts: 264
Thanks: 2
TlcAndres is on a distinguished road
Default

the problem is not the running of the script it's how it presents the data

PHP Code:
<a href="<[siteurl]>"Hello </a>
<
phpcode>
if(
true)
{
    echo(
'ello there');
}
</
phpcode
it's supposed to be presented like so

PHP Code:
Hello ello there 
instead it's being presented as

PHP Code:
ello there Hello 
TlcAndres is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:32 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design