formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Page Module #436

Open benib596 opened 5 years ago

benib596 commented 5 years ago

Hi Ben,

I have created a page in page module and gave private permission. When I opened the page its showing a blank page and the content is not displaying. And I can open the weblink of the page module is another system (again blank page) it is opening without asking any credential.

Can you please guide us.

benkeen commented 5 years ago

Hey @benib596,

What versions of the Core + module are you running? I did a test with the 3 page types - HTML, Smarty & PHP - and checked permissions for 2 client accounts, one of whom had private access to all 3 and one who didn't, and it appears to be behaving correctly in all cases.

What page type is yours? It sounds like perhaps the content of your page is invalid - either PHP or Smarty - and it's throwing an error.

You might want to also add the following line to your global/config.php file to help debugging:

$g_default_error_reporting = 2047;
benib596 commented 5 years ago

Hi Ben,

I am using core 3.0.10 and Pages 2.0.6 module version. I have tried the PHP coding which is working perfectly when I post that file into the module folder and browser directly. But through pages it is not working. Not sure if any errors in coding.

And I am getting this error.

Parse error: syntax error, unexpected '<', expecting end of file in C:\xampp\htdocs\XXX\modules\pages\view.php(20) : eval()'d code on line 1

Below is the code for your reference

<?php
/* gets the data from a URL */
    function get_data($url) {
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        //Since it is GET
        //curl_setopt($ch,CURLOPT_POST, 2); //For POST action
        //curl_setopt($ch,CURLOPT_POSTFIELDS, $POSTvars);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;   
    }
?>
<?php
    $strURL='http://temp.com/tss/27112018ses.php?itsme=1';
    $strOUT='';
    $strOUT=get_data($strURL); // Cals the pg for result 
    //print_r('HELLO');
    //$strOUT=json_decode($strOUT,true);
    //print_r($strOUT);
    //outInfo($strOUT);
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Current Sessions:</title>
</head>
<body style="background-color: #FFFFFF">
    <?php echo($strOUT); ?>  
</body></html>
<?php //var_dump($strSQL); ?>
benkeen commented 5 years ago

Ah.. I think the PHP option is pretty basic: you normally just enter PHP right within the field without the opening and closing PHP tags.

Try entering this instead:

/* gets the data from a URL */
function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    //Since it is GET
    //curl_setopt($ch,CURLOPT_POST, 2); //For POST action
    //curl_setopt($ch,CURLOPT_POSTFIELDS, $POSTvars);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;   
}

$strURL='http://temp.com/tss/27112018ses.php?itsme=1';
$strOUT='';
$strOUT=get_data($strURL); // Cals the pg for result 
//print_r('HELLO');
//$strOUT=json_decode($strOUT,true);
//print_r($strOUT);
//outInfo($strOUT);

echo <<< END
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Current Sessions:</title>
</head>
<body style="background-color: #FFFFFF">
    $strOUT
</body></html>
END;

Hmm... in retrospect, "helpfully" providing the open PHP tags was a very poor idea, as your situation illustrates.

Let me know if this works & I may revisit this to make the system provide the opening PHP tags optional.

benib596 commented 5 years ago

Thanks for the update Ben. But still I am getting the below error.

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\7servos\modules\pages\view.php(20) : eval()'d code on line 33

benkeen commented 5 years ago

Hmm... could you try just adding one line into the content for you page and see if that loads?

echo "hello world!";
benib596 commented 5 years ago

Sorry Ben. When I add only the above line it is working.

benib596 commented 5 years ago

I have removed the html content and placed only the PHP codes and it is working now

benkeen commented 5 years ago

Hmm, what a nuisance! So it appears that defining a function is a no go here. Behind the scenes, the Pages module uses eval() on your PHP code to execute it - and that doesn't allow functions. I didn't actually know this, I'll have to update the documentation.

A quick solution is of course just to remove the function from your page. Not ideal, but I think that's all we can do for the moment.