ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Forbidden Error when try to put PHP into template

October 31, 2011 4:52pm

Subscribe [4]
  • #1 / Oct 31, 2011 4:52pm

    I’m using EE v2.3.1 and have a template with PHP enabled. I can add simple PHP (ie set a variable then echo it later) but when I try to insert a “require_once” command I get a 403 Forbidden error. Again, I can go back and edit the template without a problem as soon as I remove this statement. Any ideas? I’d be happy to provide anyone with more information. Thanks in advance for any help.

  • #2 / Nov 01, 2011 11:16am

    Kevin Smith

    4784 posts

    Hi Allison,

    We can only provide limited support for PHP in templates (since it can get quite complex), but if you’d like to post your template code here, I’d be more than happy to take a look and see what help I can offer!

    I’d also recommend taking a look at your web server’s error logs to see if they reveal any information about that 403 error.

  • #3 / Nov 08, 2011 4:26pm

    davey

    27 posts

    I am in the same boat…

    I clearly don’t understand EE :-( as I can’t figure out how to get PHP to run inside a template or snippet other than a simple echo command…

    Help, where are some docs on this?

    thx-

    David

  • #4 / Nov 10, 2011 3:28pm

    Kevin Smith

    4784 posts

    Hi David,

    I’m sorry you’re experiencing so much frustration trying to get started with EE. For some help on getting PHP to run in your templates, have a look at this article in the User Guide.

    If you’d also like to post your sample template here for review, I’d be glad to have a look at it for you.

    Allison, have you got everything up and running? Or is there still something I can do to help you?

  • #5 / Nov 14, 2011 4:43am

    Sorry for the delayed reply everybody. I was away on vacation. But after doing some Googling and trolling the forums, my best guess is this is either a server issue or an EE version issue. I have an EE install on an internal XAMPP setup I use for testing and can put PHP into my templates without any issues. However, the version I use for the testing is v2.2.1 while the install I’m having trouble with is v2.2.2. Thus the only two variables I see that are different are the web servers and the versions of EE.

    I’m not really sure how to go about testing which one of these variables could be the issue. Kevin, could you speak to whether or not there were changes from v2.2.1 to v2.2.2 with regards to how PHP is rendered in the templates? As for the server difference, some other posts mention the possibility that it could have to do w/ MySQL thinking that code is trying to be “injected” when the template is saved into the DB. So basically I’m still trying to work on a solution for this problem. Thanks again for any and all help and/or suggestions!

  • #6 / Nov 17, 2011 5:58pm

    Kevin Smith

    4784 posts

    There weren’t any changes between those two versions in the way PHP is handled in templates. My recommendation for the best way to test this is to install a fresh copy of the most recent version of EE on your live server as well (using a subdomain or separate domain) and try the same PHP in the templates of that install.

    It is indeed possible that your server is trying to project against injection attempts. I’m of the mind that this is more likely caused by the server than by EE. I’ve been using PHP in my templates for ages and never had this problem.

    Keep us posted on what you find!

  • #7 / Dec 08, 2011 2:49pm

    Alright I’ve done some more testing. I took a separate EE install for a different client that was being hosted locally, moved it to the final web server and have been getting the same forbidden errors. Again, on my local setup it worked fine. All the templates start w/ a the PHP ‘require_once’ function to call in an external PHP script.

    I found that if I go into PHPMyAdmin for the web server, go into the exp_templates table in the EE database, I can manually edit the templates that way. However, this is obviously a huge pain. Can anyone shed any light as to what might be causing this or how I could fix it? This is a little over my head but its really causing me a lot of problems as updating the templates has become a grueling process. Thanks in advance for any help!

    PS I’m hosting the client sites w/ MidPhase if that helps

  • #8 / Dec 08, 2011 8:40pm

    Sean C. Smith

    3818 posts

    Allison,

    Are you not able to edit your templates via the EE control panel Design > Templates > Template Manager?
    You should also be able to access your templates as text files by following the guide here.

    Have you tried changing the PHP parsing stage? You can do that by going to Design > Templates > Template Preferences.

    Sean

  • #9 / Dec 12, 2011 4:54am

    I tried changing the PHP parsing change and still am locked out. I can’t edit the tempaltes through EE, that’s when I receive the error. Anything else you think I could test?

  • #10 / Dec 12, 2011 3:11pm

    Kevin Smith

    4784 posts

    Hi Allison,

    If you’ve got the same errors on a completely separate installation on the same server that was working properly locally, then the issue points to something the host is doing. Like I said, it’s likely a security measure. Have you checked with them to see if there’s anything that saving templates triggers with their security procedures?

  • #11 / Dec 13, 2011 1:58pm

    It’s fixed!! Thank you so much for your help Kevin! I wanted to wait to talk to the server support until I had some type of tangible grasp on the problem and this thread definitely got me there. I talked with support last night (for MidPhase - the web host) and asked them if they could check the security logs while I tried to update a template. And sure enough, there was an issue w/ Mod_Security on their end. So they fixed it and I’m good to go now. Thanks again everyone!

  • #12 / Dec 13, 2011 2:04pm

    Unfortunately now all these templates that were having the issues appear to have bigger problems:

    http://ellislab.com/forums/viewthread/206584/

  • #13 / Dec 19, 2011 2:12pm

    Kevin Smith

    4784 posts

    Whoa, sorry to see the bigger issues, Allison. I’ll follow up with you on that issue in the new thread.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases