WEB what am I doing wrong with php? v.noob question

Discussion in 'OT Technology' started by Falconer, Nov 3, 2008.

  1. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    Ok maybe I'm missing something super obvious because I basically copied this from w3schools.com but it's not working for me.

    I'm trying to use a super basic .php file and include it on another page.

    My php file (copied directly from w3schools):

    Code:
    <html>
    <body>
    <?php
    $txt="Hello World";
    echo $txt;
    ?>
    
    </body>
    </html>
    
    And then my index page:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body><?php include("phptest.php"); ?>
    <p>where is my php?</p>
    </body>
    </html>
    
    I would expect to see this output:

    But I am seeing this output:

    What am I doing wrong?

    Thanks :o
     
  2. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    try "require" instead and see if it throws an error.

    p.s. since you put <html><body> tags in the include it's going to have nested html and body tags, which is a bad thing.
     
  3. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    is your index page "index.html" or "index.php"?
     
  4. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    also, the computer/server that you're hosting it on, does it have the php module loaded?
     
  5. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    I tried both and neither worked.
     
  6. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    I'm not sure I understand what that means or how to check :o
     
  7. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    Using "require" instead of "include" yielded the same result: nothing showing up.

    So should my php file only contain:
    Code:
    <?php
    $txt="Hello World";
    echo $txt;
    ?>
    and no <html> or <body> tags? I was just copying from w3schools. Let me try that too.
     
  8. Insert Tokens

    Insert Tokens Making Cancer My Bitch OT Supporter

    Joined:
    Jan 12, 2006
    Messages:
    8,330
    Likes Received:
    76
    Location:
    Tasmania
    Do you have PHP installed on your host?

    Try accessing phptest.php directly, and see if you see "Hello world."

    As mentioned also, you don't need the <html> and <body> in your included file if it's already in your main file.

    Your included file could just be:

    Code:
    This is my header.
    
    Call it header.inc

    Then make a second file, and put all your HTML in it, and include the file:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <h1><?php include("header.inc"); ?></h1>
    <p>The header should appear above.</p>
    </body>
    </html>
    
    Call it index.php
     
  9. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,489
    Likes Received:
    70
    Location:
    Sparkopolis
    it almost definitely needs to be index.php
     
  10. TheDarkHorizon

    TheDarkHorizon \xC0\xFF\xEE

    Joined:
    Sep 26, 2002
    Messages:
    2,396
    Likes Received:
    0
    Location:
    San Francisco, CA
    Can you view source to make sure you don't see "<?php include(...); ?> in the source? If you do, it sounds like PHP isn't properly set (or set up at all) on your host. Who is your host? Can you provide a URL?
     
  11. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    It has to be .php so if you changed it back to .html, change it again.

    Also, if you're using your own computer for looking at your own web pages, then this is different just opening it in a browser. You must have php installed on your machine. Look into WAMP if you're a Windows person. If you do that, then you'll have your system up and ready to view php pages. You'll also have to view them from your site directory for it to work properly. If you're using a hosting service, then make sure they have PHP on it.
     
  12. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    Ok.

    I was testing it on my computer, so I guess I didn't have php installed.

    My host is hostgator and I'm pretty sure they allow php so i'm gonna try uploading it to there and seeing if it works.
     
  13. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    Good idea. Yes, HostGator has PHP.
     
  14. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    For this WAMP thing, is that just something I install on my computer and then it will recognize php?

    I'd like to test stuff locally before I put it online because that will be faster and easier i think.
     
  15. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
    Yes, it's very simple using Xampp lite
    http://www.apachefriends.org/en/xampp-windows.html#646
    Here's a half way decent guide on how to set it up:
    http://www.thaslayer.com/2008/01/08/easily-create-a-local-webserver-on-your-own-pc/

    The main point is once you have complete the install, you add your index.php and other files into C:\xampp\htdocs ( it is safe to delete what is already there if you'd like, it's just a testing page.)
    They then can be viewed at http://localhost/ on your computer when apache is running.
     
  16. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    i personally use XAMPP. but you just install your package on your computer and it will set your computer up as a web server. you can then access your php scripts through your web browser like http://localhost/test.php and so on.
     
  17. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    k I just installed XAMPP.

    That was like a million files :rofl:

    Ok time to figure out how to use it.
     
  18. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    just load up the xampp control panel and start the services you want to use. make sure to go through the security stuff so that everything is password protected, otherwise you'll get h4x0r3d if you're not behind a firewall.
     
  19. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    Which services do I need to use to test php? It looks like the choices are Apache, MySql, and FileZilla.

    How can I get haxored if I'm running it locally on my own computer? I'm confused.
     
  20. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    if you're just testing a simple php script with no database access then just apache is fine. if you are using a database then use mysql as well.

    filezilla is just an ftp server which you may or may not want.


    it is actually setting up your computer as a web server. in the bullet points on the security page it says "If your computer is not online or blocked by a firewall, your servers are SECURE against outside attacks." notice it says outside attacks, people inside your network will still be able to see your web server. if however you have an externally visible IP address and no firewall anyone could access your web server.

    you can change your security settings to set how others are able to access it. make sure you go through all the steps at http://localhost/security/ first thing after starting up your services.
     
  21. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    You know how HostGator is your host? Think of them having the exact same computer as you with XAMPP running it... That's all it is. Of course they do much more to optimize and secure the server. They aren't running XAMPP, but they have Apache, MySQL, PHP all on that server. It also has some different hardware, but it's not all that different. I'm just relating it to something that you would be able to understand a little bit better. A server is set up similar to how your computer is set up.
     
  22. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    Ok that makes sense.

    Are there people out there just scanning for open servers to attack?
     
  23. Falconer

    Falconer OT Supporter

    Joined:
    Jun 23, 2006
    Messages:
    65,506
    Likes Received:
    1
    btw i tried my code on hostgator and it worked :wiggle:

    I like this forum. It's super helpful. It's like the opposite of the main forum :rofl:
     
  24. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    yes

    but if you don't have an externally visible IP address they won't be able to see your web server and compromise it OR if you do have an externally visible IP address but a firewall blocking the ports your services are using they won't be able to interact with those particular services.

    by external IP i mean your computer's given IP address is an end-point on the internet and is not an internal IP address behind a NAT.
     
  25. hurleyint1386

    hurleyint1386 Someone has sand in their vagina

    Joined:
    Jan 6, 2005
    Messages:
    3,687
    Likes Received:
    0
    Location:
    Rochester, NY
    As long as you haven't played around with port forwarding on your router, you should be good... that is if you have a router. Most people do now, but I'm pretty sure there are some that don't.
     

Share This Page