Jump to content

Is this something php allows?


derrick24

Recommended Posts

Is this something php allows? This code works on php5.1.2 and 5.2.5. Seems to break on some 5.2.* versions The zip file contains the full set of files.

 

<?php

print "<strong>Welcome to the site, attempting to include file.</strong><hr>";

// Test1
require_once("includes/index.php"); // this file is at wwwroot/includes/index.php. The path is not wrong as this file is pulled into the root of the site iteself.
if (hello() == true) // Hello sits inside "includes/index.php"
{
	print "include worked.";
}
?>

 

[attachment deleted by admin]

Link to comment
Share on other sites

Is the code you posted the index.php within the page directory? If so, you need to use...

 

<?php

print "<strong>Welcome to the site, attempting to include file.</strong><hr>";

// Test1
require_once "../includes/index.php";
if (hello() == true)
{
	print "include worked.";
}
?>

 

Yes, your path is wrong.

Link to comment
Share on other sites

Im not getting an error. the function "hello()" simply does not work or run. I'm sure this has reference to this bug: http://bugs.php.net/bug.php?id=9673

 

to elaborate: I use this directory structure for one of my sites and my hosting company has upgraded to 5.2.2 and is no longer working. They seem to feel that I should rewrite my code. I'm not prepared, nor do I have the time to do that especially if this is a bug in that ver. of php.

Link to comment
Share on other sites

Sorry Thorpe its not wrong. The code you are viewing here is pulled into the root of the directory. So everything is referenced from the root.

 

Bare in mind this code works on certain version of php and breaks on others. Namly the 5.2.* vers up to 5.2.5 from what I can tell so far.

 

 

 

wwwroot/

  - Includes/

    - index.php (Holds hello function)

 

  - pages

    - page

        - index.php ( Holds the code: include("includes/index.php"))

 

  - index.php ( pulls in pages/page/index.php)

 

 

 

 

So the above structure becomes:

 

wwwroot/

  - Includes/

    - index.php (Holds hello function)

 

  - index.php ( now includes "pages/page/index.php" and runs the code:    include("includes/index.php")  )

 

 

 

 

so now we have :

 

wwwroot/

 

  - index.php ( thats has: "pages/page/index.php"

                    and "includes/index.php"  all together )

 

 

 

 

 

 

 

Link to comment
Share on other sites

The structure works as follows, its a type of drill down.

 

wwwroot/

  - Includes/

    - index.php (Holds hello function)

 

  - pages

    - page

        - index.php ( Holds the code: include("includes/index.php"))

 

  - index.php ( pulls in pages/page/index.php)

 

 

So the above structure becomes:

 

wwwroot/

  - Includes/

    - index.php (Holds hello function)

 

  - index.php ( now includes "pages/page/index.php" and runs the code:    include("includes/index.php")  )

 

 

so now we have :

 

wwwroot/

 

  - index.php ( thats has: "pages/page/index.php"

                    and "includes/index.php"  all together )

 

Link to comment
Share on other sites

LOL. I was just going to suggest that the include path might be different when they upgraded and might not contain a dot .

 

From the manual -

 

Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script
Link to comment
Share on other sites

Yeah, as suspected the path is broken. I'm not 100% sure on windows but it needs to be...

 

.;C:\Apps\PHP5\Pear

 

Paths are seperated by ; and you need the . (dot) to be the first, it points to the current (working) directory. Tell your host to install and configure php properly.

Link to comment
Share on other sites

There is a bug I recall reading in the php5 change log concerning the include_once/require_once having some problem in remembering where or what file they already included, but I think the net effect was that if you had more than one folder with the same name file it included the wrong one.

 

I recommend browsing the php change log to see if there is any relevant information. Using the newest php version is always preferred instead of an earlier one. The current is 5.2.5.

Link to comment
Share on other sites

I cant find a link to 5.2.2 anywhere on php.net only the latest ver. ( but I have managed to get a copy of 5.2.2 now. Just have not testes it yet) and yes 5.2.5 works fine but my host does not seem to want to upgrade to it.

 

Ill probably have to change hosts or get my own box.

 

I also went through the change logs, there is something there about php includes not working from 5.2.* and been fixed in php 5.2.5.

 

http://bugs.php.net/bug.php?id=41822

 

I'm sure its the problem.

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.