Help with php files using html templates.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kiosk2
Forum Newbie
Posts: 3
Joined: Fri Sep 04, 2009 4:14 pm

Help with php files using html templates.

Post 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 :oops:

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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with php files using html templates.

Post 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

Code: Select all

var_dump($path);
display?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help with php files using html templates.

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with php files using html templates.

Post by jackpf »

Surely it wouldn't make a difference to include() (or the other include functions) though??
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help with php files using html templates.

Post 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).
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Help with php files using html templates.

Post 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?
kiosk2
Forum Newbie
Posts: 3
Joined: Fri Sep 04, 2009 4:14 pm

Re: Help with php files using html templates.

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with php files using html templates.

Post 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.
kiosk2
Forum Newbie
Posts: 3
Joined: Fri Sep 04, 2009 4:14 pm

Re: Help with php files using html templates.

Post 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");
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with php files using html templates.

Post 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.
Post Reply