Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to add a file to this script?

    hi
    this is my code wich when i type myfile.php?action=blahblah
    i will display the content in the code
    PHP Code:
    <?
    $action 
    $_GET['action'];

    function 
    test() {
    echo 
    '<a href="index.php"><font colour="#FFFFFF">home</font></a>
    blah blah blah'
    ;
    }
    if (
    $action == "test") {
    test();
    }
    ?>
    this works fine but i want to include a file so instead of having to type all of the content in the code it will be in that file

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    256
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you mean you want to save the function in a separate file and include it into your script, you need to use include_once() or require_once()

    If that is not what you mean, you will have to rephrase the question, because it is very vague.

    http://uk.php.net/include_once

  • #3
    New Coder
    Join Date
    Jul 2006
    Location
    Portugal
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Create a file, let's say include.php with your content:

    Code:
     <?php 
    
    function test() { 
    echo '<a href="index.php"><font colour="#FFFFFF">home</font></a> 
    blah blah blah'; 
    } 
     
    ?> 
    And then, your index.php would look like:
    Code:
    <?php
    include 'include.php';
    
    $action = isset($_GET['action']) ? $_GET['action'] : ""; //-- To avoid undefined variable notices
    
    switch ($action) {
       case "test" : { 
         test(); 
      }break;
    }
    ?>
    
    Last edited by thunderhoster; 08-27-2006 at 07:57 PM.
    Liked my post? want my help in a project? MSN: geral'at'brunobernardino.com

  • #4
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks
    what i was looking for


  •  

    Posting Permissions

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