Solved

variable was used before it was defined

Posted on 2008-09-29
6
573 Views
Last Modified: 2012-05-05
Hi,
I always get this message from Zend Editor saying : "This variable was used before it was defined" with an orange curvy line below it. what does this exactly mean and how do I define a variable before I use it?

best regards,
0
Comment
Question by:Shopies
  • 3
  • 3
6 Comments
 
LVL 4

Expert Comment

by:Ara-
ID: 22596163
I don't know this Zend Editor, but many programming languages require / recommend that you declare a variable before using it. That means that you specify what kind of value the variable can hold (and of which size) before you assign a value to it. In PHP however the variable is declares as it first appears and is assigned a value. I guess this is a warning in Zend Editor and that it doesn't have any effect really. The script works?
0
 

Author Comment

by:Shopies
ID: 22596233
Well let me clarify something here. I'm building a login system and all the control panel files must check if the bariable $user_name is assigned or not. If yes, then the admin could use the control and if not it will prompt him back to login form or it should be. When I tried to add "index.php?act=idx&user_name=pah" in the address bar it logged me in without prompting me to the login form although I didn't login. Here is a Snippet of my .php header files which is located in the very top of my .php files
		

		if(!$user_name) {

			$log = new TemplatePower("temps/login.htm");

			$log -> prepare();

			$log -> printToScreen();

			EXIT;

		}

Open in new window

0
 

Author Comment

by:Shopies
ID: 22596240
I really don't know how to define the variable "$user_name" other than this way.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Accepted Solution

by:
Ara- earned 500 total points
ID: 22596354
OK. Know I understand why you get that message. You should use the isset function:
http://no.php.net/manual/en/function.isset.php

0
 
LVL 4

Expert Comment

by:Ara-
ID: 22596393
I would also use post instead of get when dealing with a login-system. Would need some more information about how it is supposed to work etc. if I was to help you more.
0
 

Author Comment

by:Shopies
ID: 22596717
Thank you so much. exactly, the thing that I missed was the function isset and when I used it the problem has been resolved.

Many thanks buddy ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

914 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now