Solved

variable was used before it was defined

Posted on 2008-09-29
6
564 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

757 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