We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21395
    • 91 Posts
    For some time now I’ve noticed that very long snippets, when I attempt to save them, fail, and I am presented with the 404 page from the front end.

    I got round it by saving the code as something.php and doing an include. Good practice anyway, perhaps. Puzzling but no big deal. I made a desultory attempt to find out why, but can’t see anything here, or in JIRA.


    Now, today, a very small snippet won’t save.

    And it is something to do with "fclose".

    Curious, no?

    Here’s the snippet that won’t save:

    <?php
    global $modx;
    $result=$modx->db->select('email','ccdnsw_web_user_attributes');
    if( $modx->db->getRecordCount( $result ) >= 1 ) 
    	{
    	while( $row = $modx->db->getRow( $result ) ) 
    		{
    		$output .=$row['email'];
    		}
    	}
    $fp=fopen("assets/upload/memberlist.csv", 'w');
    foreach ($list as $line) 
    	{
    	fputcsv($fp, split(',', $line));
    	}
    echo debug1;
    fclose($fp);
    echo debug2;
    ?>


    While this one saves perfectly:

    <?php
    global $modx;
    $result=$modx->db->select('email','ccdnsw_web_user_attributes');
    if( $modx->db->getRecordCount( $result ) >= 1 ) 
    	{
    	while( $row = $modx->db->getRow( $result ) ) 
    		{
    		$output .=$row['email'];
    		}
    	}
    $fp=fopen("assets/upload/memberlist.csv", 'w');
    foreach ($list as $line)
            {
    	fputcsv($fp, split(',', $line));
    	}
    echo debug1;
    echo debug2;
    ?>


    The only difference is the

    fclose($fp);

    statement at the end.

    I know the script is broken - I wanted to correct it online - but I have to get MODx to save it before i can call it.


    Is this a bug?


    Evolution 1.0, r5601
    PHP 5.2.5
    MySQL 4.1.22
    Browser Firefox 3.5.3
      MODX Revolution 2.6.5-pl (traditional)

      Hosted on MODX Cloud

      Skype: nicbaldeagle
      • 26903
      • 1,336 Posts
      You don’t say waht your webserver is but are you running mod_security by any chance?. If so this is a known issue
        Use MODx, or the cat gets it!
        • 21395
        • 91 Posts
        My own htaccess file doesn’t load mod_security, and this is what the System Info screen reveals:

        SERVER_SOFTWARE Apache/1.3.39 (Unix) mod_bwlimited/1.4 mod_auth_passthrough/1.8 mod_log_bytes/1.2 FrontPage/5.0.2.2635 DAV/1.0.3 mod_ssl/2.8.30 OpenSSL/0.9.7a

        So I don’t think my ISP is running it for me.

        Do you still think it could be mod_security? I searched the entire System Info output and it isn’t mentioned.

        I think it’s a new bug. Any takers? If not, I’m off to JIRA to post it there.



          MODX Revolution 2.6.5-pl (traditional)

          Hosted on MODX Cloud

          Skype: nicbaldeagle