View Full Version : PHP Includes Within PHP
Jamie
March 5th, 2006, 12:25
I use the same form mailer throughout all my Web sites, but for some reason it spews out errors when I use PHP includes within the script.
See http://www.bluemoonstudio.co.uk/formmailer.php for example
I have always solved this by forgetting the include, and simply replacing it with the end code, but I don't want to do that this time, because it defeats the whole purpose of using PHP includes. Equally, I don't want to have a page with nothing but a white background and "Thank you., We will get in touch". I want this to be incorporated in to the design to keep a consistent design.
So, how do I go about stopping these errors, while still been able to use PHP includes? I seem to remember using a combination of forward and backward slashes within the include would work, although I did try it and it didn't work.
I have a feeling this is very basic PHP. Somebody please make me look like a fool by telling me how to solve it! :lol:
ethicaldesign
March 5th, 2006, 15:38
The error that you're getting there is a syntax error Jamie. It looks like you have an extraneous '<' character hanging around in the php code somewhere (though it's hard to know for sure without being able to see the code).
If you have a look at line 20 on that page, or around line 20 you should find it I think.
If not if you can email me the code I can have a quick look at it for you and see if I can spot it.
Jamie
March 5th, 2006, 15:44
Thanks for your reply John.
The '<' character which it is referring to is the start of the PHP include. This error doesn't appear until I start adding the PHP form mailer script. I have had these errors appear before, where a PHP script doesn't like PHP been put inside it, but I can't for the life of me remember how to solve it, without removing it.
ethicaldesign
March 5th, 2006, 15:58
You should be able to use includes within includes without any problem (I do that all the time for including functions).
The error seems to indicate your formmailer.php script is the problem though. If there's an error inside an include file, it'll usually list the name of the include itself with the error message.
You should have something like:
require('includedfile.php');
or if it's to go in amongst the html
<?require('includedfile.php');?>
in your main page, then inside your included file you should have:
<?php
at the top before any php code, then
?>
at the bottom after any php code
Is that the case?
If you can post line 20 from that formmailer.php script I may be able to spot it.
the_pm
March 5th, 2006, 15:59
Jamie, you shouldn't need to add anything into the formmailer.php script. Just point to a "success" page within the [0] config area, and be done with it :)
Jamie
March 5th, 2006, 16:02
I think you misunderstood what I'm trying to do John. That isn't your fault. I'm finding it hard to explain. Give me time to think of a better way to describe it.
Jamie, you shouldn't need to add anything into the formmailer.php script. Just point to a "success" page within the [0] config area, and be done with it
I *could* do that, but that looks very unprofessional for the visitor. When the form is submitted all they see is a horrible white page with a bit of Times text on. I want to be able to keep the design on that form processing page, rather than just having a blank page. To do this I need to use includes (like the rest of the Web site does) but the page doesn't like includes been put in amongst the form script.
I'm sure you know what I mean Paul, because I used my root WHM powers to look at several of your form mailer pages, and you have simply used no styling. It is just a white page with the outputted thank you text.
the_pm
March 5th, 2006, 16:03
Jamie, there's a variable within that form that allows you to redirect people to anoter Web page. Create a success.php page with your text in it, just like any other page in the site, and then set that variable. I believe it is the last variable in the set that you're supposed to change.
Jamie
March 5th, 2006, 16:05
Ah balls! Why didn't I see it? <Slap!> I'll take a look now Paul. Thanks!
ethicaldesign
March 5th, 2006, 16:08
No, I think I know what's happening. You've got a < character somewhere within a block of php code somewhere that shouldn't be there. If it was within the html it wouldn't show this error and would just render the page with the extra < in it as a character in the output. So the error indicates that it's in some php code somewhere.
What method are you using for including? You're not using ssi style includes like:
<!--#include file="something.php" -->
are you?
ethicaldesign
March 5th, 2006, 16:08
Ahh..Looks like you've beat me to it. :)
Jamie
March 5th, 2006, 16:13
Thanks guys. It is now working perfectly. It isn't actually a site I run, it is one of Tjobbe's, so it will be a nice surprise for him when he gets back. :)
the_pm
March 5th, 2006, 16:15
Jamie, did you get an updated form to use? FormM@iler was recently rereleased to handle injection issues. If your version is less than 2-1/2 months old, it should be fine. If not, the form will remain vulnerable!
Jamie
March 5th, 2006, 16:22
I'll take a look now Paul. :) Thanks for letting me know.
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.