The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 2 of 2

Thread: [php] re-declare function error

  1. #1

    [php] re-declare function error

    This is how my site works: Index.php is the shell of the site. It has all the graphics and layout tables. Each link is structured like index.php?sec=contact. I use $_GET to find which section the user wants to go to. And then I load the page content by running secCode(). secCode() is the function in contact.php, for example, that contains all the contact content.

    PHP Code:
    $section $_GET['sec'];
    $section .= ".php";
    I've done include("constants.php") in index.php, but whenever I load a whateverSection.php, the constants are no longer in scope. So I re-include constants.php within the section code. This is where the re-declare error lies. How do I fix it?
    Last edited by NeoDreamer; January 18th, 2007 at 01:04 AM.

  2. #2
    there's no reason to include your files more than once. really, you should probably be using require_once instead of include. if you require constants.php at the top of your index you should be fine.

    also, your current method is a big security risk. you should be validating that GET request. and you should take your variables out of double quotes. use single quotes for strings. something like this should work:

    PHP Code:
    require_once( 'constants.php' );

    $validSecs = array(

    in_array$_GET['sec'], $validSecs ) ) {
    $_GET['sec'].'.php' );
    else {
    'home.php' );


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012