ionCube Logo
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


 
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder

Dynamic generated PHP Files

Author Message
iCOM



Joined: 12 Jul 2016
Posts: 6

PostPosted: Fri Sep 16, 2016 8:54 am    Post subject: Dynamic generated PHP Files Reply with quote

Hello,

in my application, i want to replace my own template engine with a fully fledged solution (for example, i'm looking at 'Twig' right now).

Unfortunatly these solutions all seams pretty slow, if not using cache (dynamic generated PHP files).

My Problem:

I use the following parameters for securing my source code.

--property "key=value"
--include-if-property "key=value"

Now, if i would enable template chaching, i will get problems with including these dynamic generated PHP files.

Is there a solution i haven't found yet? Maybe to specify a trusted include path or something like that? Or Maybe someone has some nice ideas to overcome this?


Thank you very much!
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2771

PostPosted: Fri Sep 16, 2016 6:06 pm    Post subject: Reply with quote

Try encoding the file in the template engine that loads the templates with the property but not the include-if. That ensures that the template loader can load the plan text files, and the loader itself will be usable by other files because it still has the necessary property to satisfy the include-if requirement.
_________________
Community Admin
Back to top
View user's profile Send private message
iCOM



Joined: 12 Jul 2016
Posts: 6

PostPosted: Mon Sep 19, 2016 8:50 am    Post subject: Reply with quote

Works like a charm,

Thank you very much!
Back to top
View user's profile Send private message
grupowebex



Joined: 18 Dec 2015
Posts: 2

PostPosted: Thu Nov 03, 2016 8:31 pm    Post subject: solution Reply with quote

Replace this to encode cache. Working on encoded/nonencoded app.
lib/twig/cache/filesystem.php

Code:
/**
     * {@inheritdoc}
     */
    public function load($key)
    {
        if ( ioncube_file_is_encoded() )
        {
            $ioncube_encrypt = false;
            eval('?>' . ioncube_read_file($key, $ioncube_encrypt) );
        }
        else
        {
            include_once $key; 
        }
    }

    /**
     * {@inheritdoc}
     */
    public function write($key, $content)
    {
        $dir = dirname($key);
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
                throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
            }
        } elseif (!is_writable($dir)) {
            throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
        }

        $tmpFile = tempnam($dir, basename($key));
       
        $ioncube_encrypt = true;
        if (ioncube_file_is_encoded() && false !== ioncube_write_file($tmpFile, $content, $ioncube_encrypt) && @rename($tmpFile, $key)) {
            @chmod($key, 0666 & ~umask());

            if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
                // Compile cached file into bytecode cache
                if (function_exists('opcache_invalidate')) {
                    opcache_invalidate($key, true);
                } elseif (function_exists('apc_compile_file')) {
                    apc_compile_file($key);
                }
            }

            return;
        }
        elseif (false !== file_put_contents($tmpFile, $content) && @rename($tmpFile, $key))
        {
            @chmod($key, 0666 & ~umask());

            if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
                // Compile cached file into bytecode cache
                if (function_exists('opcache_invalidate')) {
                    opcache_invalidate($key, true);
                } elseif (function_exists('apc_compile_file')) {
                    apc_compile_file($key);
                }
            }

            return;
        }

        throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
    }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum