Apache problems on windows

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Apache problems on windows

Post by paqman »

hey I'm trying to set up Apache to run php files on my windows xp computer. It all went fine, I ran Apache and was able to open the php file in Internet Explorer. The only problem is the pages won't work right. The main page, index.php, works by

Code: Select all

include($page.".php");

(links are index.php?page= )

It just won't include any files. It works fine on the internet, but won't on my computer. Is there something I haven't configured or something else I have to download? thanks!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You might want to search this forum for a "debugging 101".. If we don't have it, it would go like this:

Start with instructing php to report all errors and warnings:

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
Next, test if $page contains what you want: (After a while you might want to switch to using a debugger)

Code: Select all

echo "page should contain: $page";
You will probably experience that the $page variable seems to be "gone". A search on the web (or this forum) will return many links to people that have experienced the same.

The solution is probably to use $_GET['page']. (Setting register_globals=on isn't a solution on the long term)
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Post by paqman »

I searched for other people with this problem but I couldn't find anything. Sorry, I'm completely new to having php and apache on my computer, where do I put those first 2 lines of code? Into the php command prompt? I tried displaying the variables like you said and nothing was there, like you said, and using GET did work. Is there any way to make the php less touchy (not needing all the extra code)?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

First of all when you include, PHP will read a file somewhere on the filesystem. Like all files you may need to spacify the entire path to that file.

So if you have all PHP file in C:\Apache\htdocs\, and all page files in \includes\ folder. You may need to use something like:

Code: Select all

//might be a good idea to strip slashes/periods this contains (a url injection could alter the path that's actually used
$page = $_GET['page']; 

include_once('C:\Apache\htdocs\includes\' . $page);
You could always use require() rather than include(). include will not produce an error if it cannot locate your file, require() will create an error - and is therefore far more useful from a bug catching perspective...
Post Reply