#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    Is there anyway to print html code without
    having to use a 'printf' or an 'echo'. I would basically like to copy and paste the code into my scripts without having to add all of the PHP syntax. It can be very time consuming.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    63
    Rep Power
    14
    You can mix PHP and HTML code in the same file.

    eg.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    $somevar = 1;
    if($somevar > $someothervar) {
    ?>
    HTML SCRIPT HERE
    <? } ?>
    [/code]

    Or even

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <? if($something) { ?><B>print something<? } ?>
    [/code]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    Thank You. I guess I'm a little to used to Perl. Can you use 'include()' or 'require()'
    to place headers and footers into pages?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Yep.

    My pages all follow the same simple design

    <? include "header.php4"; ?>
    The page only contains the meat of the page, anything between <body> and </body>. You could also do a
    <? include "body.php4"; ?>
    <? include "footer.php4"; ?>

  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    11
    Rep Power
    0
    What do the 'include' files look like? Are they just html code with .php4 extensions?
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London, England
    Posts
    16
    Rep Power
    0
    You can keep the .html extension if you like and if you have any <?php .. ?> in there it will be processed too.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Some are straight html, others have PHP in them. In one case, I do a query to find a users name, department and other info, and create a page based on that data.
    examples:
    header.php4
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <?
    mysql_connect($db_location, $db_user, $db_pass);
    $query = "SELECT * FROM user_data where entity='$entity' and user_id='$user_id'";
    $result = mysql_db_query($user_db, $query);
    if ($result) {
    while ($r = mysql_fetch_array($result)) {
    $user_id = $r["user_id"];
    $entity = $r["entity"];
    $department = $r["department"];
    $security_level = $r["security_level"];
    $department_id = $r["department_id"];
    }
    }
    ?>
    <title><? echo "$department"; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <STYLE TYPE="text/css">
    <!--
    CSS Stuff.
    -->
    </STYLE>
    </head>
    <body>[/code]

    The query will run everytime the page loads, but thats okay for me.
  14. #8
  15. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    I use one include file, database.php3, to define all of my connections to the database. I use another, functions.php3, to define all of the functions I use on the page, showing forms, messages, and validating info. Using it for header and footer files is a good idea, also. whatever you use it for, it gives you one file to modify when you want to change something, and it takes affect in all of the pages that include it.

    My $0.02

    ---John Holmes...
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0
    Hi,
    As long as the file that you use the include() in has the php, php3, or php4 extention. Then the file that you include can have any extention (i.e. myfile.inc or myfile.txt) and it will work...

    ------------------
    2 Samuel 7:10 Moreover I will appoint place for my people Israel, and will plant them, that they may dwell in a place of their own, and move no more; neither shall the children of wickedness afflict them any more, as beforetime,
  18. #10
  19. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Actually, it's better to name you include files with a .php extension. If I had my database connections in a file database.inc, then if someone found out the name and loaded it into a browser, they would see the text and my login/password to get into the database. If it's named .php, then they wouldn't see anything.

    Another option is to place the include files out of the web root.

    ---JH
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    15
    If you placed a .inc outside the web root, how could the browser find it?

    I tried this once using ../include.inc - where include.inc was located one level above the web root - no dice.

  22. #12
  23. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    I was on the php listserve for awhile and that was always the advice they gave, to put the file outside of your web root. I don't know why it wouldn't find it, it's PHP looking for it, not the web server. Maybe the folder that it was in didn't have the correct permissions or something, but it should work. either way, you want to make sure that a user can't just type in the name of your include file and see the plain text. a file with .inc will just be given as plain text. i found out someones login and password to their database this way, once. since most people use include.inc or database.inc, it's not to hard to find it.

    My $0.02.

    ---JH

    PS. I just tried it and it worked. I put include.inc outside of my www root. I included with ../includes/include.inc and ../include.inc and both worked.

    [This message has been edited by SepodatiCreations (edited September 16, 2000).]

Similar Threads

  1. Good devlopment IDE for PHP that indents code
    By grover in forum Development Software
    Replies: 5
    Last Post: May 6th, 2004, 07:36 AM
  2. How to write a PHP script to remove a file?
    By xmxpcom in forum PHP Development
    Replies: 2
    Last Post: February 16th, 2004, 05:58 PM
  3. How to see the Memory used by a PHP script?
    By Pardall in forum PHP Development
    Replies: 4
    Last Post: February 13th, 2004, 03:54 PM
  4. php script to change pop3 password?
    By jensm in forum PHP Development
    Replies: 0
    Last Post: February 13th, 2004, 02:45 PM
  5. Replies: 0
    Last Post: February 8th, 2004, 10:11 PM

IMN logo majestic logo threadwatch logo seochat tools logo