+ 7
How to load a PHP page and then check it for errors prior saving it?
I want to check if a PHP page has errors prior saving that page on the server. Now I have tried exec method, but it is blocked by my webhosting. Can I save page to a local file and then use curl_init / curl_exec to get the page response and try to parse for php errors? I mean is it possible to use local file with curl_init? Just to be more clearer, pages are created/ loaded and changed by another PHP page (an editor). So in WYSIWYG editor user creates a PHP page and save it to the server, I want to check if that page is without errors before saving it. Thanks, Dejan
8 Respuestas
+ 5
I have figure it out with curl:
excerpt:
....
$data = $_POST['editordata'];
try {
file_put_contents(APPPATH . "views/test.php", $data);
$ch = curl_init(base_url() . "/test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
if (strpos($content, 'A PHP Error was encountered') !== false){
echo '<div class="dont-break-out" style="color:palevioletred">' . $pages_val . ' ' . $this->lang->line('page_with_error') . '!</div>';
}
else {
....
+ 5
George S Mulbah thank you, but the site I've built is online CMS that allow users to create new php pages, it is the feature and can't be revoked or cancelled. For me is now important to find the solution, so if no curl can help then some plugins will or an iframe whatever
+ 4
Shudarshan Rai 👑 how do you mean local server? That is online like CMS, when user is editing/creating php pages that are part of a website. When user create a page with bad syntax then that page opens with a php error. But, ok I will try to use curl to programmatically load the page and try to search for errors on the response.
+ 4
Why you people are not reading my question? Do you understand what I want to do? George S Mulbah , do you understand what I am trying to accomplish?
+ 1
//Use local server for test then
+ 1
Php is a server side language ,so I advice you
Download local server like Xamapp try to test your page ok
+ 1
Php is a server side language ,so I advice you
Download local server like Xamapp try to test your page ok
+ 1
I read your question well, it is possible but I will not advice you do that because sometime you tend to experience authentication errors from the curl_int which might just lead you to think the page contains errors that why I recommend you using Xammapp as it allow you be in full controls