My PHP code runs fine on HostGator server, will not on new localhost!

really need some help here guys,

BACKGROUND:
3 year old localhost was running fine but was lost (motherboard failure). have now started over with WAMPServer 2.0 (I think it’s about 3 years old too). my PHP code that is running just fine on the HostGator servers doesn’t like the new localhost.

getting all kinds of warnings about variables and indexes being initially undefined, but they’re just warnings, and we execute anyway and all is well. BUT…

PROBLEM:
I’m getting NOTICE(S) about variables and indexes being undefined, and code executes unpredictably. for example: I define/initialize $daycounter = 0; and then (php) INCLUDE a file that uses the $daycounter variable, and get the NOTICE “variable undefined”. so what the hell is the problem here? all things are identical except it’s localhost - not HostGator server!

any ideas at all are greatly appreciated!! I have a ton of code and cannot go through it all. this localhost has to run just like the production environment! PLEASE HELP!

thanks for your time!

Compare the error reporting settings on the two servers, maybe HostGator is not reporting the warnings:

http://php.net/manual/en/errorfunc.configuration.php

thanks captian! I don’t see error reporting is the issue. the problem is my code executes fine on HostGator, and unpredictably on this new localhost. how can showing or not showing WARNINGS be the problem? I have turned off ALL warnings on localhost and code does not execute right.

Check your PHP versions. You may be running the new PHP5.4 on WAMP and possibly PHP5.1 or PHP5.2 on your host if it’s old. A lot changed between the two. I would personally turn all errors ON and ensure that they’re displayed (display_errors in the PHP.ini file) in order to see what’s going on.

What exactly do you mean by “code does not execute right?” Is it just the warnings or are you getting different results or what?

example: I have table based calendars that are generated on the fly, but not anymore… can’t execute calendar properly because a simple counter variable is not defined. see details below please:

I’m getting NOTICE(S) about variables and indexes being undefined, and code executes unpredictably. for example: I define/initialize $daycounter = 0; and then (php) INCLUDE a file that uses the $daycounter variable, and get the NOTICE “variable undefined”. so what the hell is the problem here? all things are identical except it’s localhost - not HostGator server!

so in this example it’s like the variable I define is not being recognized by the calendar building file I call immediately with my INCLUDE calendar-build-file command

PHP is lazy. It lets you get away with not defining a variable, so you could do something like:


<?php
if ($foo == $bar){
    $page = 'mypage.html';
}

include($page);

It would work if you have notices hidden from the error_reporting value, but will complain if you don’t. This is because $page is defined inside a condition that may not have been met. Only if $foo == $bar would $page become defined and therefore the error will not occur. You can hide the errors, or you can go back and fix the code.

However, that will just hide the message. It should still work otherwise. So you’ll need to investigate why it’s not being defined and what the implications are in that event

so it’s not just the warnings. the code cannot execute properly because of missing variables.

Try hiding notices and see if it makes a difference. If not then you may need to go back and fix the broken code. I would also check those PHP versions. A lot changed at PHP5.3, so if you were running a pre-5.3 on your host and you’re running >=5.3 on WAMP (you should be with WAMPServer) then that could also be the problem.

:nono: There really is no need to swear.

By the way, if I get weird errors, I tend to place debug outputs throughout the code and possibly even have it die on certain conditions so that I can assess the state of the code at any given point. If you have a suitable dev environment (xdebug etc) you can use breakpoints etc, but frankly it’s usually easier to just put a simple var_dump() in a few places and see what you get in return. It sounds like the logic may not be quite what you think

my local WAMP is 5.2.9
HostGator version is hard to pin down, but will ask them directly.
was hoping for a simple obvious fix, but it looks like this could be a real can of worms…
PLUS I got a notice from HostGator a few days ago about how they are going to upgrade their servers soon. so what is there and has been working for 2 years may start behaving just like my localhost!!! I will be screwed big time!!!

also relevant: HostGator is Linux, my localhost is Windows. my OS is WinXP Pro 64 bit…

5.2.9? That’s VERY old (released in Feb 2009). It may be that you’re going the other way then, ie your host may be running a newer version. All you need to do is to call phpinfo() on the server (ie in a script that you upload) to see what version you’re running

Something that may be relevant then, since you’re running Windows locally: Linux uses a case-sensitive file system, Windows does not. Usually that means that things work on Windows but not on Linux though (ie where you include(“file.php”) on Windows but the file is actually File.php)

now we’re getting somewhere that makes sense! will check on that. got to run my son to the dentist now. will do later this evening.

THANK YOU ALL VERY MUCH !!

By the way, you can download add-ons for WAMP that allow you to switch between PHP versions. You might want to look at whatever version you have on your host and matching them as closely as possible. Even better, if you can, get a copy of the PHP.ini from your host and try to configure them as closely as possible too. There’s a chance that you may not have certain modules enabled that you have on the other, some maximum file size settings etc. Bit tricky to match them precisely when one is Windows and one is Linux, but you should be able to get them very close. Also, I don’t know what version you’re running, but IIRC you may find yourself with problems if you’re running 64-bit software on your Windows box. There aren’t a lot of 64-bit modules available for Windows, and you can’t mix and match 32 and 64 bit modules. You’re usually better to stick with 32-bit on Windows. Honestly, it’s unlikely that you’ll need the advantages that 64-bit brings on a home dev server anyway

Kinda talking to myself a little here, but another point to consider is that WAMP appears poorly supported these days. It’s actually not hard to install the Apache and PHP binaries for Windows and configure it yourself. I always used WAMP in the past, but the advantages over running your own individually installed copies are outweighed by the poor support IMHO. You could try XAMPP as well as I understand it’s better supported than WAMP

If for any reason the include file is not included then any variables defined in it will be undefined. Include() only generates a warning which you might not have noticed. Replace the include() with require() and if the file is missing the script will stop.