Ioncube: Is it possible to encrypt an specific function within a PHP file - ioncube

I have a file called sample.php, that file has PHP and HTML code. I only want to encrypt the PHP function within that file using ioncube. Is it possible?

Related

How to access html file inside iframe in production

I am creating a web app where, this app will generate a .html file in public/ directory. And after that i want to show that generated html file on a page using iframe .
I am using NextJS for this task. I have configured next.config.js for rewrites but getting 404 error. I am using Railway for hosting. Since in Vercel we can not access filesystem here.
Instead of generating html dynamically, if I upload that .html file, then i can access that file using iframe in production.
I think we can not access those files which were not available during build process. (this is my guess , maybe wrong)
How can I solve this problem or should I use another framework ?
Thanks
Since I was accessing .html files (i.e <iframe src="path-to-file"></iframe>) which were not available during build process, that's why i was getting 404 error.
So I did the following thing:
suppose I want to do this <iframe src="/pdf/page01.xhtml"></iframe> where file location is in public/pdf/page01.xhtml.
so this src is sending a GET request to localhost:3000/pdf/page01.xhtml.
To manipulate this request I created a pages/api/pdf/[...slug].js. In this file you can use process.cwd() to access the file inside your public dir. You read file content using fs.readFile and send the response res.status(200).send(data) like this.
By doing this I was getting the desired result.
Suggestions are always welcome.

How to define Wordpress global variable for use in a REST Controller?

I'm extending the WP REST API by writing a Controller class.
I'm trying to read the config for this class from a file, e.g:
{
"base-namespace": "myapi",
"version": "v1",
"resource": "things"
}
This would allow me to keep server and client in sync as they would both use the same config file.
However, I do not want WP to stay reading this file for every request it serves... Currently, if I read this file from anywhere in the plugin file (or any of its required files - including the Controller definition), and if I also echo out where I'm reading, I see it's always passing through that bit of code (including the reading) for every request.
I imagine I need to read this file somewhere outside the plugin itself - make it a global, and then access it when instantiating the Controller.
I'm new to WP - this is the first time dabbling with it. Where should this global variable definition go such that it's only executed once?
Note:
I have tried using require_once in my plugin to require a config file which does the file reading. I had put an echo statement there and it shows that that file gets executed for every request (despite the require_once).
I have also tried wrapping the file reading in an if(!isset($my_global_var) statement. But adding an echo statement inside the if statement shows that this global variable is always unset with every request served... clearly this needs to go in some kind of WP startup file which only gets executed once.
Thank you.
Store your config data as a PHP array in a .php file and then include it using the PHP include statement. Advanced PHP engines parse the PHP source once and cache a compiled representation of the script so that it does not have to re-parse the PHP sources everytime. So if your data is inside a PHP source file it would be saved in the PHP's engine compiled script cache.
Of course if your client is non-PHP it would need to have code to parse a PHP array.

how to specify drupal mail save file module's directory path?

I have installed above mentioned module.
It works fine, my doubt is how to mention current year in file directory field. Since, I would like to get mails saved in sub directories in format : year/month/date
Try writing your own hook_file_presave() function and hook file saving path:
https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_file_presave/7.x
See what you have in that $file variable passed to the function, try somehow to detect that this module is saving the file and in that case change file path the way you want.

Creating a new file without using a ServletContext

Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.

uploading files - how to store file in non public folder

I have problem with uploading files. I followed these instructions: http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html and everything is working fine, but I want to save uploaded files in a folder that is not public and with random name and then send it to the browser in original name.
I know how to put file in non public folder with random name and how to save original name to database, but what should I do next for getting this file content and send it to browser with original name? How to achieve that?
Store the hidden path in the database, then just read it in your php script that is public available and send your file to a user, if you don't how to send files in php, you can find it out here on stackoverflow.

Resources