PHP include files

I wrote a .php page, (well, threw the php into an html widget), to populate our staff directory. It uses a database connection with an include file that it should read to connect to the database. The include file is in our Assets folder. When I load the page on the site, it will not connect or read the include file. If I don’t use an include file and just toss the code into the html widget to connect, it works fine. Any idea if I can use include files within php within html widgets?

Sarah,

Good afternoon, and thank you for reaching out to the community. You brought up an interesting question.

With regard to the include file. Have you done a full site publish? If not I believe that the file that it is referencing, may not have been sent out to the webserver yet? If you can verify that the file is in fact on your webserver, and has been published, then I would think it would be a matter of checking the url path it is referencing.

Let me know if that helps, or we can communicate more offline, and create a support ticket.

Chris

Yep, full site publish is done. It will not read that connection that I’m creating. I’m still stumped.

Sarah,

Lets continue this offline, can you fill out a support ticket on zendesk? I want to see the exact way you are creating this asset, and the code you are using, and hopefully together we can figure a solution out for you.

Chris

Doing some research internally, we have some suggestions for the community regarding php includes. Below was the response:

My first suggestion, being under the presumption you want to keep the connection string outside the page, so the “wrong element” can’t see your connection properties, and paste the url into their web browser? If that is the case, the best practice would be to configure your Apache web server to have this connection file sit outside the document root directory.

http://stackoverflow.com/questions/23…

This would allow content living on your website to have access to the connection script, but not allow outside users to access to it. Utilizing this approach, this connection script would be outside Percussion. This approach would also have the benefit of users of Percussion, not being able to see the connection properties within the CMS.

The 2nd option, and to address why publishing the asset folder (where the connection script lived) did not function correctly, was that Percussion publishes “Pages”. These pages are assembled upon publish. They take binary files (like a rich text and/or HTML widget) out of the asset folders, and merge them into the page/template upon publish. So to reference the staffdirectory.php page, if you dragged that connection script (html widget) into it, it would be merged into the page (check the source code to verify) after publish. (Which I believe you also said does work).

Using this knowledge the 2nd way to handle this as a php include, would be to create a blank template and page and drag this connection file (html asset) into it. Once the page would be published you could reference the “page” as a php include on your staffdirectory.php page, then this would work.

Thanks, Chris. When I have some time, I’m going to go for the first option, but the second option worked perfectly. So, I can always fall back on that.

Sarah,

Glad I could help! Message me and let me know when its done, I would love to see the finished product :slight_smile:

Chris