SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A few basic Php questions

    Ok, before I get started I want to say that I already asked about php basics about a month ago and got great responses from very skilled webmasters in here. I have a few questions that I find important to ask, and I would really apreciate it if some of you could take the time to answer any of them.

    1- I know that in order for php to actually be able to communicate with a database the file needs to be named.php even if its 99% html. My question is if html will still work properly if no PHP is typed inside it but I still named the file "xxxx.php". For example, lets say that I have a complete website made in html and only one of the pages includes php codes. But I dont want the site to have .html in some pages and .php in others. I want the whole site to be .php. Will the html code work even if the whole site is .php or would it be better if I only name the page with php .php and have the rest of the pages that have no php remain .html? (Sorry if that was a bit confusing)

    2- How exactly does a webmaster receive the info people type in the php forms a website has? I mean, do you place your email in the code and receive the info there, or is it more complex than that?

    3- When I make a website on html, I just go to the webhost and place the images in the "images folder" and the code in the "public html folder".But how does it work with php? Lets say I have just a bit of php code inside an html page and I want that bit of php coding(a contact form for example) to work properly. Do I have to make any other changes on the webhost to get that php code to work?

    Thanks in advanced for reading this.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,189
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)

    questions

    1. If all the pages are only HTML except the one, I don't see any sense in changing them to PHP files that the server will have to process for no reason. If it bothers you to have only one file ending in php (and I doubt if that many users would notice let alone be bothered by it) maybe you could use apache to rewrite requests for really_a_php_file.html to really_a_php_file.php to preserve consistancy.

    2. I have contact form info emailed to me. But It doesn't get used that often. If you think this way might swamp your email client, you may want to store the info in a database so you could view it when you want to. Either way, make sure the form can't be used to send SPAM from your site by someone mis-using it, or will let someone do a db injection attack.

    3. Can't really say. I guess you'll find out what you need to do for your particular host when it needs to be done.

  3. #3
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1- Yes, that will work, although will cause a (very) slight performance hit as your HTML will be run through the PHP parser. Also, you could configure your server to run .html (or .js or .foo or .whateeveryouwanthere) file through the parser as well, thus allowing you to use PHP inside a .html file. (I sometimes do this with .js files, allowing my to do some parsing of my JavaScripts server-side.)

    2- It's slightly more complex than that. Your HTML form needs to submit to a PHP file (via either GET or POST, the latter being the preferred method), then your PHP script will access those variables via the $_GET or $_POST (depending on which method you use) superglobal arrays. Your script can do whatever it wants with these values, from as simple as echoing them back to the user to the more complex like inserting into a database or e-mailing you. Best to decide what you want to do with the data and then come back with specifics if you can't figure it out on your own.

    3- Assuming your web server is set up correctly (if you're on a hosted account somewhere that supports PHP, it's already set up correctly), then your PHP scripts go the same place your HTML files would go. In this respect, you can think of PHP as HTML on steroids. And Red Bull. And HGH. And speed. And... well, you get the idea.
    PHP questions? RTFM
    MySQL questions? RTFM

  4. #4
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. You won't have any problems here; although there will be negligable performance penalty as the HTML will still be parsed by the PHP engine.

    2. While this is a possibility using some formmail script, it's more common for the form data to be sent to a backend PHP file for processing. Often this processing takes the form of validation and sanitisation and then insertion to a database. You can either post form data using the GET or POST HTTP methods. The GET method will be familiar as this is where the name/value pairs are appended to the URL like e.g. '...page.php?var1=1&var2=b'. The POST methods sends the data in a separate packet and not in the query string; this method is most common for form processing for security among other things.

    3. If your host has installed PHP and setup Apache/IIS so it sends php files to the php engine, then you need do no more. If someone requests a PHP page, the http server will notice this and pass the request to PHP to deal with. PHP will then spit back some HTML for the http server to return.

    I would recommend you purchase or borrow a book or two on PHP. I would definately recommend PHP and MySQL Web Development - a very good book!

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!!. And yes my host has php and apache installed.I also installed wamp on my computer but dont really know how to use it yet. Thanks again everyone, truly helpful forums!

    I will definetly buy that book mmanders, thanks for the link.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •