Jump to content

Help writing my 1st PHP Class


TomTees

Recommended Posts

So I don't need a "PHP Header" like you need to define an HTML block?

 

And for my simple registration form, I guess most if not all of my file will be HTML?

 

Is it a sin if you had 100% HTML in a file called MyFile.php?

 

(I was just taught in the past to make all your files ".php" for consistency...)

 

Nope, you don't need any kind of starting tag/header/preprocessor call/etc. at the beginning.  There's a small caveat with HTTP header redirects, but you're not even close to needing to worry about that.

 

For your form file, unless you're going to add PHP to it later, I'd just keep it as a straight HTML file.  Why make the server do more work than it needs to do to render the page?  I wouldn't be worried about file extension consistency.  It's much better to be consistent with actual file names and your directory structure.

Link to comment
Share on other sites

To add to Nightslyr's response, HTML tags are just that - HTML tage which tell the browser how to render the page. The browser has nothing to do with PHP code and doesn't know how to process it. The idea behind PH (and other server-side code) is that the server will process the server-side code and output a complete HTML page to send to the browser.

 

Here is an example php page (date.php):

<html>
<body>
The date today is <?php echo date('F d, Y'); ?>
</body>
</html>

 

When a user requests the page date.php the page will first be processed by the server (html files normally go strait to the user). The PHP processor will look for any PHP codeblocks and process the code. In this instance, the processor will echo (i.e. print) the current date where indicated. The completed page (consisting of only HTML content) is then sent to the user. The final HTML code would look like this:

<html>
<body>
The date today is August 20, 2010
</body>
</html>

 

The user who views the page would only see that content if they were to "view source" on the displayed page.

Link to comment
Share on other sites

Thanks Nightslyr and mjdamato for your responses.

 

I think I'm going to unfortunatelt go break down and re-buy the book I have on HTML and CSS in storage.  (I'm a book guy and it looks like I need to sit down and re-read all of this stuff again to start sounding intelligent.  UGH!)

 

So maybe after I get these super basic questions down better, I can pick up with getting help on tying my web pages to back-end classes that do processing.

 

To be continued...

 

 

 

TomTees

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.