Solved

Undefined variable problem

Posted on 2009-05-16
2
220 Views
Last Modified: 2012-05-07
yikes, this is a bit of a mess.

I'm moving my sites to a new server.  The new server has php5, (my old one just php4), but I can run sites through php4 via cgi.

On one of the scripts I am trying to run on the new server (using php4 for now), goes like this:

-------
if (!$loc){ //start if
 $time='<FONT COLOR="#223D75" STYLE="font-size: 13px">- time will appear here -</FONT>';}
--------

I'm getting an error like this:
---------
Notice: Undefined variable: loc in /home/mysite/public_html/data/wwc.php on line 5
--------

What do I do about that?  I mean, my whole 'if' test is to see if it has a value, and if it doesn't, do such and such.  

Do I need to write this differently, or change something in php.ini (it worked on my old server), or is there something else?

Thanks,  Chris

ps: the goal is to get all my sites php5 compatible, but I put them on php4 for now just to get them going so I can work on them.  I did try this site on php5 and got lots of errors, so I backed off and just going to try the smaller issues until I get everything moved.

0
Comment
Question by:St_Aug_Beach_Bum
2 Comments
 
LVL 11

Accepted Solution

by:
climbgunks earned 500 total points
ID: 24404570

If it's a new server you're testing this against, it may be a registers_global setting that is different.  Fortunately, if it is there are a number of ways around it, either by modifying your code, or adding an entry to your .htaccess file..

See this article for much more info on this problem:

http://forums.devarticles.com/php-development-48/php-undefined-variable-error-from-form-to-script-5156.html
0
 

Author Closing Comment

by:St_Aug_Beach_Bum
ID: 31582298
Thank you climbgunks,

I didn't get an answer from that page, per se, but it did lead me down the path of investigating .htaccess more closely, and I realized that I had

AddType application/x-httpd-php .php .php4 .php3  .html .htm

in .htaccess, and:

AddHandler php4-script .php .htm .html

in the httpd.conf file (to get the php4 cgi working).

Wondered if that might cause some problem, so I took it out of .htaccess and voila, things are working :)

So thanks for getting me going in the right direction!

Chris
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question