 |
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |
11-14-2006, 07:06 AM
|
#1 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
[PHP] Undefined Index??
Okay, out of all of my years in PHP, I've never came across this before.
Here is the error:
Notice: Undefined variable: i in E:\wwwroot\onwswimming.net\index2.php on line 3
I'm not sure why it's coming up, it doesn't make sense.
Here is the background:
I developed this website originally on my webserver, which is a Red Hat Linux server with PHP & MySQL. Since they wanted to buy their own hosting, I had to move it over to their new web server for them. The server I moved the site + database to is a Windows IIS with MS SQL (PHP Installed). I don't know the error came up, the versions are the same, and it doesn't have anthing to do with the database extension for PHP I had to install for MS SQL.
So, has anyone came across this error and know how to fix it?
Also, I have done the isset() function on other occasions, but you can't do this for isset():
Code:
if(isset($i == "logout")) {
}
So, is there another variable in place to do this? I've never came across this error, EVER! So, it's a whole new thing to me unfortunately.
Server info: http://onwravens.net/phpinfo.php
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
Last edited by Izzmo; 11-14-2006 at 07:18 AM..
Reason: Change Title
|
|
|
11-14-2006, 11:15 AM
|
#2 (permalink)
|
|
Senior Member
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
Latest Blog: None
|
You are using two kinds of checks in your control structure: isset and ==. I believe in this case the isset is what's causing your error whenever variable $i has not been initialized.
Code:
if($i && $i=="logout") {
would be the extended illustration of (perhaps) what you are trying to do. In practice, would have the desired result. Not only must $i have been initialized, but it also must have the value "logout". If $i is neither, it won't match.
|
|
|
11-14-2006, 11:19 AM
|
#3 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
It's weird, because I've never had this problem before, so I'm trying to see why.
I just gave the isset() function as an example that will not work, so.
The original function I had was
Code:
if($i == "logout") {
...
}
This did not work... so I'm trying to figure out why?
Doesn't that seem perfectly logical, it should work?
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-14-2006, 11:49 AM
|
#4 (permalink)
|
|
Senior Member
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
Latest Blog: None
|
It does seem logical. What's the code that's initializing $i?
|
|
|
11-14-2006, 11:54 AM
|
#5 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
Well, it's not necessarily being initialized.
Here is what is happening. I have it setup so if I user wants to logout, the Admin, the url will be index2.php?i=logout.
In the code, it check to see if i is set to the string: logout. If it is, it checks to see if the admin cookie is set, and if that is set, it will log them out and erase the cookie.
Here are the two sites: exact same code.
http://www.onwswimming.net/index2.php
http://www.izzmo.com/swim/index2.php
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-14-2006, 12:04 PM
|
#6 (permalink)
|
|
Senior Member
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
Latest Blog: None
|
Hmmm. PHP 5.x ... well ... thinking aloud ... register_globals is being handled a little differently than with v.4.x, and it generally prefers a variable to have been initialized before use (general practice, but loosely enforced), so maybe try
Code:
$iA=0; //init temp var
$iA=$_GET["i"];
if($iA=="logout") {
?
I realize that $i _seems_ to have been initialized by its inclusion in the $_GET array, however maybe this is where the snafu lives ... in the translation between the two ...
|
|
|
11-14-2006, 12:07 PM
|
#7 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
Wow, I didn't even notice my server still had 4.4.3 on it...
They must of reinstalled it lol, cause it was version 5 a couple weeks ago.. hmmmmmm. This is the time I wish I had my dedicated server back
I'll try that StupidScript, thanks.
I'll inform you if it works or not.
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-14-2006, 12:18 PM
|
#8 (permalink)
|
|
Senior Member
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
Latest Blog: None
|
Quote:
|
They must of reinstalled it lol
|
I wonder if they rolled back because of broken scripts? 
|
|
|
11-14-2006, 12:21 PM
|
#9 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
Lol, not sure exactly. I know they are bent on only installing stable versions, so maybe it wasn't stable enough? Not sure.
It's amazing how many changes the PHP Team does. I just looked at their ChangeLog, and they have to be doing at least 500 changes/fixes each version.
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-14-2006, 12:36 PM
|
#10 (permalink)
|
|
Senior Member
Join Date: 09-22-06
Location: Los Angeles
Posts: 663
Latest Blog: None
|
Ahhhh ... I love the smell of progress in the morning ... 
|
|
|
11-17-2006, 12:20 AM
|
#11 (permalink)
|
|
v7n Mentor
Join Date: 04-07-06
Location: Manchester, NH
Posts: 722
|
Code:
if(isset($i == "logout")) {
}
By order of evaluation this code is asking:
Is the equivalence of $i to "logout" a "set" variable?
The question (immediately above) doesn't make sense. We cannot ask if equivalences are set, we can also ask if they are true or false.
($i=="logout") returns a boolean. That boolean is passed to isset, which expects a variable.
First Evaluation: $i has the same contents as anonymous string "logout"
Possible Returns:
- true
- false
- I don't know, $i is not set <<< crash
Second Evaluation: has the variable in the isset argument been initialized?
Evaluation:
if $i=="logout" then this evaluates to:
if (isset(true)) {
if $i != "logout" then this evaluates to:
if (isset(false)) {
if $i is not set then this evaluates to:
if (isset(error thrown when comparing empty var to string))
In all three cases we haven't passed isset what it wants, which is an address in memory that either is or is not initialized.
You could replace that with this:
Code:
if (isset($i)) {
if ($i=="logout") {
logout();
}
}
|
|
|
11-17-2006, 08:14 AM
|
#12 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
I know this doesn't work. I said above, that it doesn't work and I was wondering why.
The actual code I had in my site was the second example you showed.
But with PHP 5.x, this is not possible, and since they made it more 'explicit', you have to set the variable i before you ask about it. Which makes sense.
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-17-2006, 10:54 PM
|
#13 (permalink)
|
|
v7n Mentor
Join Date: 04-07-06
Location: Manchester, NH
Posts: 722
|
I don't follow you Izzmo. If the code I suggest is the code that's on your site then what is the problem? Are you saying you can no longer say:
Code:
if (isset($varname)) {
The whole point of that function is so that you don't have to be explicit.
|
|
|
11-17-2006, 11:30 PM
|
#14 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
Well, this functionality works in PHP 4.2.x, but in the new 5.x versions, they changed it so you have to state the variable before you use the isset() function now. Which is odd, but I'm still doing some checking around on this.
Once again, it works fine for me on my server, which is 4.2.3, but on my clients servers, it is 5.x.x, so I have to do some research on it.
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
11-19-2006, 01:51 AM
|
#15 (permalink)
|
|
v7n Mentor
Join Date: 04-07-06
Location: Manchester, NH
Posts: 722
|
oh like
Code:
var $login;
if (isset($login))
instead of
Code:
if (isset($login))
var $login;
?
|
|
|
11-19-2006, 06:23 AM
|
#16 (permalink)
|
|
v7n Mentor
Join Date: 11-01-03
Location: Kansas City
Posts: 1,330
|
Well, something along those lines, yes.
__________________
█ Izzmo
█ Coding Guru Extraordinaire
█ ZeroWeb Hosting & Design - Customizable hosting for every type of user!
|
|
|
|
Currently Active Users Viewing This Thread: 5 (0 members and 5 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:52 AM.
© Copyright 2008 V7 Inc Powered by vBulletin Copyright © 2000-2009 Jelsoft Enterprises Limited.
|
|
|