Page 1 of 1
Help with php files using html templates.
Posted: Fri Sep 04, 2009 4:34 pm
by kiosk2
Hi everyone
If I may just briefly introduce myself, I am David and live in Bolton in the UK. I am learning PHP "on the fly" and hope you accept dumb questions from a complete novice here
I wonder if someone may be able to help me with a problem I have, I'll do my best to explain.
On a script I have the main files are php but use includes to html template pages.
I wish to display the site path to a directory when I browse to the php file.
The actual line of text I wish to display on screen is:
include_once("/home/sites/user/public_html/member/3rdpartysession.php");
If I use only the php file I can type:
Code: Select all
include_once("<?php echo $path; ?>member/3rdpartysession.php");
This works fine. But I need to enter the above code in the html template file. If I do that though it displays:
include_once("member/3rdpartysession.php");
missing out the actual <?php echo $path; ?> part because it's in the html page I guess.
Is there a token I can use in the html page code to replace the php echo $path; ?> part? If so, do I need to add anything in the php file to make it work?
Many thanks in advance for your replies.
Regards
David
Re: Help with php files using html templates.
Posted: Fri Sep 04, 2009 6:39 pm
by jackpf
Hmm...
If the template file is being included using one of PHP's many include functions, or executed with eval(), or whatever, then the code should be executed....and whatever is in $path will be displayed. Where is $path actually set?
What does
display?
Re: Help with php files using html templates.
Posted: Fri Sep 04, 2009 10:06 pm
by califdon
What is the filetype of the template file? If it's .html, nothing is telling the web server that it should parse the file. You might try renaming that template file.
Re: Help with php files using html templates.
Posted: Fri Sep 04, 2009 10:13 pm
by jackpf
Surely it wouldn't make a difference to include() (or the other include functions) though??
Re: Help with php files using html templates.
Posted: Fri Sep 04, 2009 10:16 pm
by califdon
I'm not sure, perhaps not, I was just tossing that in as a possibility. I honestly don't have a good grasp on exactly how include files are handled (other than the obvious fact that they can be included in other files).
Re: Help with php files using html templates.
Posted: Sat Sep 05, 2009 2:14 am
by cpetercarter
Califdon is right. If you give a file an .html ending, then it will be sent to the browser "as is" and any php bits will not be parsed. What happens if you replace the .html termination with .php?
Re: Help with php files using html templates.
Posted: Sat Sep 05, 2009 4:12 am
by kiosk2
Thanks guys
What I am trying to achieve is to display in an admin menu, the server path to a file (member/3rdpartysession.php) so that they know what code to enter on their own sites.
As the admin menu uses an include to a html template file for content I need to have the code in the html file.
The actual text the user will see on screen will be:
include_once("/home/sites/user/public_html/member/3rdpartysession.php");
To acheive this I can use:
Code: Select all
include_onceinclude_once("<?php echo $path; ?>member/3rdpartysession.php");member/3rdpartysession.php");
where $path displays the server path to the sites public_html folder and this would work if it was in a php file but as it needs to go in the html it is not parsing the <?php echo $path; ?> part.
I hope what I'm asking makes sense. I guess I need to know what code to put in the html file so that it will echo the sites server path.
Many thanks for your help
David
Re: Help with php files using html templates.
Posted: Sat Sep 05, 2009 7:06 am
by jackpf
What's the code that's including the template?
Also, what's in the browser source? Do you actually see <?php echo $path; ?> in the source?
cpetercarter wrote:Califdon is right. If you give a file an .html ending, then it will be sent to the browser "as is" and any php bits will not be parsed. What happens if you replace the .html termination with .php?
I still don't think it matters since the user isn't accessing the html file through the webserver. It's being included by PHP.
Re: Help with php files using html templates.
Posted: Sat Sep 05, 2009 7:28 am
by kiosk2
jackpf wrote:What's the code that's including the template?
Also, what's in the browser source? Do you actually see <?php echo $path; ?> in the source?
cpetercarter wrote:Califdon is right. If you give a file an .html ending, then it will be sent to the browser "as is" and any php bits will not be parsed. What happens if you replace the .html termination with .php?
I still don't think it matters since the user isn't accessing the html file through the webserver. It's being included by PHP.
Thanks Jack - it's:
Code: Select all
$GetFile = file("../html/admin/3rdparty.html");
By the source do you mean what can you see in the browser? If so, the <?php echo $path; ?> is just blank so it displays exactly:
include_once("member/3rdpartysession.php");
Re: Help with php files using html templates.
Posted: Sat Sep 05, 2009 8:28 am
by jackpf
What, are you then using a foreach loop to display each line or something?
Try using include() instead. Or at least eval() the contents.
And by the source, I mean, what you see if you right click, view source, in your browser.