Results 1 to 6 of 6

Thread: PHP Required

  1. #1
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post PHP Required

    Hi, in my site i am using PHP Require to show my Meta description and keywords, this gets the information from to external files, one for description and the other for keywords. Is it alright to use PHP Require to get information for the meta tags from an external file or is there any other better way to get the information for the tags?

  2. #2
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    By getting the tags do you mean like:
    PHP Code:
    <?php
    echo '<meta tags="' . require("tags.php"); . '" />';
    ?>
    If so that should work as long as the tags are alright, if it doesn't then you will have to do this:
    PHP Code:
    <?php
    require("tags.php");
    ?>
    and on tags would be the meta tag...

    In case you don't know, if the file can't be found then the page will not load... so i suggest using include like this...

    PHP Code:
    <?php
    include("tags.php") or echo("Could not load tags");
    ?>
    Hope this helps...

  3. #3
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post

    yes the tags are
    PHP Code:
    <?php
    require("tags.php");
    ?>

  4. #4
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Code:
    <?php
    require("tags.php");
    ?>
    It is ok to get any code, html, text, etc. from external files.

    For the above code to work, tags.php must be in the same directory as the page that requires it, or, it is in the php include directory.

    For something like meta tags and keywords, I would use include(); instead of require();

    Use require when the file you are calling is CRITICAL to the function of your page, otherwise, use include. Database connection, a file with functions, etc. may be things you would want to use require(); for. You can also use require_once(); and include_once(); as their are usually no negative consequences to doing so.

    Good luck.

  5. #5
    Join Date
    Feb 2007
    Location
    West Yorkshire, United Kingdom
    Posts
    145
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Post

    Thanks, but im also wanting to know if the page title and the two meta tags, keywords and description. Can Be in one external php file for all the websites pages to get that information from.

  6. #6
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Yes. Absolutely. You could even take it a step further and do this:

    header.php:

    Code:
    <!DOCTYPE html 
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    	<head>
    	
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <meta></meta>
                    <meta></meta>
    
    		<title><?php echo "$title"; ?></title>
    		
    		<link href="css/reset.css" rel="stylesheet" type="text/css" media="screen" />
    		<link href="css/typography.css" rel="stylesheet" type="text/css" media="screen" />
    		<link href="css/forms.css" rel="stylesheet" type="text/css" media="screen" />
    		<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
    		
    		<link href="css/print.css" rel="stylesheet" type="text/css" media="print" />
    		
    	</head>
    		
    	<body class="<?php echo "$body_class"; ?>">
    And in footer.php:

    Code:
              <div id="footer">
                   <p>My common footer.</p>
              </div>
    
         </body>
    
    </html>
    And then in index.php:

    Code:
    <?php
    
    $title = "Home";
    $body_class = "home";
    
    include('header.php');
    
    ?>
    
    <div id="content">
    
         <h2>My index.php content</h2>
    
    </div> <!-- end content -->
    
    <?php
    
    include('footer.php');
    
    ?>
    And in about_me.php:

    Code:
    <?php
    
    $title = "About Me";
    $body_class = "about_me";
    
    include('header.php');
    
    ?>
    
    <div id="content">
    
         <h2>My about_me.php content</h2>
    
    </div> <!-- end content -->
    
    <?php
    
    include('footer.php');
    
    ?>
    etc etc etc...
    Last edited by JasonDFR; 11-10-2008 at 06:16 AM.

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
  •