Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
basic philosophy, where to put php code
Old 10-27-2008, 01:02 PM basic philosophy, where to put php code
Average Talker

Posts: 25
Trades: 0
In summary: Where can I put PHP code?

My first attempt at PHP embedded this into an htm file:
<?php
phpinfo();
?>
It did not work. A conversation with the tech people that host site resulted in putting just that in a dot PHP file. It worked.

Where can PHP code be put? Does it have to be in a dot php file, or can I make PHP function calls from a dot htm file? Are there any restrictions in putting HTML code in a dot PHP file?

A link to a place that discusses this will be just as appreciated as a directl answer.
bkelly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-27-2008, 01:23 PM Re: basic philosophy, where to put php code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The extension of a filename tells the server how to handle that file. If you insert php into a .htm file, the server will not know that it needs to parse that php code (in your case at least).

Regardless, however, of whether or not a file is htm or php, the html contained in that file will be handled the same way, so it is best just to use .php that way the server will know that the file contains php code. There are no restriction to putting html in php files, the extension only tells the server that the file contains php.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-27-2008, 01:26 PM Re: basic philosophy, where to put php code
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
If the site is hosted on Apache, you can configure .htaccess to parse whatever file extension you like as PHP. EXAMPLE.

By default, only .php files are parsed as PHP.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-27-2008, 01:30 PM Re: basic philosophy, where to put php code
Average Talker

Posts: 25
Trades: 0
My first read gave me the impression that:
<?php
stuff
?>

Says: "Hey server, be aware that there is some PHP code here." To me that says it should not matter.

So I'll work on the concept that the extension must be dot php.

Is there a way I can "call" a php file from an htm file such that the php code puts its text in the htm stream and sends it to the user?

Thank you.
bkelly is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 02:24 PM Re: basic philosophy, where to put php code
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
To me that says it should not matter.
Think resources conservations.
Limiting the parsing only to files with .php helps minimizing the impact on file that will not need to be parsed.
It's more a hint to the server saying "hey, that file here needs to be parsed", as opposed to "Check everything everywhere to find if you eventually have to do something".

When the servers gives 10'000~500'000 requests per days, it's nothing for him to parse everything.
Now, make that 1'000'000 requests per hour, and I can assure you that the time the web server takes to parse files that would not be needed can be used with much more efficiency elsewhere.

That's why apache can filter which files will go through the PHP engine.
And why the default is to send only the .php* files (php3, php4 and php5 should be interpreted too, I think)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-27-2008, 02:32 PM Re: basic philosophy, where to put php code
Average Talker

Posts: 25
Trades: 0
Quote:
Originally Posted by NullPointer View Post
http://tinsology.com/ - Under construction
I tried to PM you but was prohibited. Your PHP link gave me a 404.
bkelly is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 02:54 PM Re: basic philosophy, where to put php code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by bkelly View Post
I tried to PM you but was prohibited. Your PHP link gave me a 404.
That site is something that has been on the back burner for a while. I was in the process of creating a personal blog from scratch to work on my jsp coding but then I got caught up in school.

You have to have a certain number of posts before you can send PMs I believe. If you have a php question you may want to just create a new thread, there are lots of people who are just as or more knowledgable in that regard than I am around here.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-27-2008, 04:36 PM HTML Headers
Average Talker

Posts: 25
Trades: 0
Hopefully understanding the above, when I went back to editing my site, I realized that I don't know what to do with the standard HTML headers. For example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

Where do I put all this in a PHP file. Does is go inside or outside the <?php ... ?>
bkelly is offline
Reply With Quote
View Public Profile
 
Old 10-27-2008, 05:17 PM Re: basic philosophy, where to put php code
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Think of PHP like an html generator.
What should always be present, you put outside of the PHP blocks.
Put into PHP only what needs to be processed by PHP.

Keep it simple.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-27-2008, 05:18 PM Re: basic philosophy, where to put php code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Only php code should be inside of the <?php ?> symbols. The only time html should appear within <?php and ?> is when it is stored as a string for php to output (ie echo). You can treat your php just like you would any other html file. Headers should still be the first thing you output, though php code that does not have output can be placed above your headers and in some cases needs to be.
PHP Code:
//example file
<?php
session_start
(); /*sessions are an example of things you need to do before sending headers*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title?></title>
</head>

<body>
<?php
//php code can be inserted within your html
echo $content
?>
</body>
</html>
That's just an example of how you insert php into an html document. A php file does not necissarily contain any html, nor does it have to contain any php code. The <?php ?> symbols are a way of telling the server that it needs to start parsing your code. Anything you output from php will be treated as html.

Say you have a file test.php containing the following:
PHP Code:
<body>
<?php echo 'Hello<br />World'?>
</body>
When a user requests that file (meaning they navigate to test.php) their browser will recieve the following:
Code:
<body>
Hello<br />World
</body>
PHP is server side code. This means that someone visiting your site will never see php code nor do they need to be aware that page is coded in php. HTML is client side code meaning it is parsed by the user's browser.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to basic philosophy, where to put php code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.70832 seconds with 12 queries