Jump to content

Redeclaration errors


menwn

Recommended Posts

Hello all,

 

I am at a complete loss. For the past months I am developing a web site. I have the web site running at my Windows pc at home (where I mainly develop it and run it on Apache 2 with PHP (i think 5.3.x or 5.2.x) ) and I have it running live at the web server. I also have a macbook that I develop the same web site occasionally. I am using XAMPP and php 5.3.1 in this case.

 

I keep the code between my two computers (Mac and Windows) up to the same level using SVN (which runs on a linux machine).

 

What I have done a billion times before and in this case also is having the basic libraries included with require_once in one file called "baseincs.php" and then at each file I only include with require_once this one php file. This has been working for years perfectly and in this particular case has been working for months on the exact same code. Yesterday I wrote some (completely irrelevant, HTML GUI mostly) code on the Windows pc and uploaded it to the SVN.

 

Today being at work I downloaded the SVN update to my mac and out of the sudden I get redeclaration errors on every page (beginning with the index.php).

 

I cannot figure this out. I am positive I have not changed anything(!!!) on the index.php or the baseincs.php. I know that these error will manifest if you use include or require instead of include_once and require_once and you include the same file in multiple places in your code. This has not happened. Here is the code from the baseincs.php

 



require_once 'config.php';  //sets various defined parameters application-wide
require_once('session.inc');
require_once('errors.inc');

require_once('bootstrap.php');
require_once('usermanager.inc');
require_once('loginproc.inc'); // sets g_loggedInUID


/**
* If you don't actually generate any UI in your page, then
* just don't instantiate the HtmlGenerator class ....
*/
require_once('htmlgen.php');

 

and here is the beginning of the index.php file

 

ob_start();

require_once 'libraries/coreincs.php';
require_once 'libraries/utilitymanager.php';

//global $g_loggedInUID;
if($g_loggedInUID !=-1)
{

$name = Users::fullNameFromUserID($g_loggedInUID);

}

 

Finally the code where I get the first error is the session.inc file and it follows

<?php
//only comments above here
/**
*=-----------------------------------------------------------=
* nuke_session
*=-----------------------------------------------------------=
* This function completely destroys a session and all of its
* data after we have logged a user out of our system.  In
* addition to destroying the session data, we destroy the session
* cookie and also make sure that $_SESSION is unset.
*/
function nuke_session()
{
  session_destroy();
  setcookie(session_name(), '', time() - 3600);
  $_SESSION[] = array();
}

/**
* One of these sessions can last 60 minutes
*/
ini_set('session.gc_maxlifetime', 3600);
session_start();


/**
* Try to prevent session fixation by ensuring that we created
* the session id.
*/
if (!isset($_SESSION['created']))
{
  session_regenerate_id();
  $_SESSION['created'] = TRUE;
}

/**
* Try to limit the damage from a compromised session id by
* saving a hash of the User-Agent: string with another
* value.
*/
if (!isset($_SESSION['user_agent']))
{
  /**
   * create a hash user agent and a string to store in session
   * data and user cookies
   */
  $_SESSION['user_agent'] =
      md5($_SERVER['HTTP_USER_AGENT'] . USER_AGENT_SALT);
      
  setcookie('ag', $_SESSION['user_agent'], 0);
}
else
{
  /**
   * verify the user agent matches the session data and
   * cookies.
   */
  if ($_SESSION['user_agent'] !=
          md5($_SERVER['HTTP_USER_AGENT'] . USER_AGENT_SALT)
      or (isset($_COOKIE['ag'])
          and $_COOKIE['ag'] != $_SESSION['user_agent']))
  {
    /**
     * Possible Security Violation.  Tell the user what
     * happened and refuse to continue.
     */
  
    throw new SessionCompromisedException();
  }
}
?>

 

Fatal error: Cannot redeclare nuke_session() (previously declared in /Users/andreass/MySites/projectoarc/oarc/libraries/session.inc:35) in /Users/andreass/MySites/projectOarc/oarc/libraries/session.inc  on line 38

 

As you can see this is not true for session.inc

 

Please note that the exact same code works on my Windows PC. Any help will be much appreciated!!!!

 

Regards,

menwn

Link to comment
Share on other sites

Is the error message you posted exactly the error that is being output, with no alterations, over-typing?

 

If so, you have two folder branches on your mac/unix machines, but only one on your Windows -

 

projectoarc vs projectOarc because your max/unix are case sensitive operating systems and windows is not.

 

Edit: Also, php.net has had a reoccurring problem with getting the _once versions of require/include to actually be able to tell if the same path is actually to the same file (though this should cause your Windows system to experience this problem and not the case-sensitive operating systems.)

Link to comment
Share on other sites

Interesting. Yes you are correct and problem was sovled with the only note that the projectOarc directory does not exist. It turned out that I had declared it like that in the vhosts.conf file of XAMPP for the domain I have set up locally but I did not expect such an error to give me redeclaration issues. I would expect the domain not to run at all as it was pointing to a non existent document root (if I went to a test page e.g. www.oarc.dev/test.php it would work correctly for this particular wrong directory root.

 

Maybe your edit about the php.net seems to be to some relevance to my issue but I could pin point it exactly. I mean the require_once in my case was the only that could not understand that the file was the same but since I had XAMPP looking at a non existent directory how the rest of the site (the test.php) run???

 

Shouldn't it just say directory not found? Especially in an operating system like Mac or Linux.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.