SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    514
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Compare the error reporting settings on the two servers, maybe HostGator is not reporting the warnings:

    http://php.net/manual/en/errorfunc.configuration.php
    Denny Schlesinger
    web services

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    514
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What exactly do you mean by "code does not execute right?" Is it just the warnings or are you getting different results or what?
    Denny Schlesinger
    web services

  6. #6
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP is lazy. It lets you get away with not defining a variable, so you could do something like:

    Code php:
    <?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

  9. #9
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so it's not just the warnings. the code cannot execute properly because of missing variables.

  10. #10
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    514
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    so what the hell is the problem here?
    There really is no need to swear.
    Denny Schlesinger
    web services

  12. #12
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  13. #13
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!!!

  14. #14
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also relevant: HostGator is Linux, my localhost is Windows. my OS is WinXP Pro 64 bit...

  15. #15
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  16. #16
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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)

  17. #17
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 !!

  18. #18
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  19. #19
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    England
    Posts
    695
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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

  20. #20
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    514
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by m300zx View Post
    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
    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.
    Denny Schlesinger
    web services

  21. #21
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem FIXED with old XAMPP 1.7.1 from 2009.
    don't know why though... it also runs PHP 5.2.9 same as old WAMPServer that did NOT work!
    found out HostGator is running 5.2.17 maybe PHP version isn't the issue??
    oh well... I'm happy, and thank you all (especially Antnee) again for pointing me in the right direction!


Bookmarks

Posting Permissions

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