Page 1 of 1

XAMPP Undefined Index - $_SESSION, $_POST, $_GET, $_REQUEST

PostPosted: 29. January 2012 01:36
by yodrica
Hello all, this is my second time installing XAMPP onto my Windows XP OS, and I didn't have this problem before.

I'm trying to make a Google Chrome tab to make users' experiences with Chrome more personalized.

I just started it, and so I decided to start functions.php:

Code: Select all

Here is the error that I am getting:
Notice: Use of undefined constant username - assumed 'username' in C:\xampp\htdocs\chrome\functions.php on line 2

I've searched around, and have found no answers. Again, I did not have this problem with XAMPP before, at least, I don't think I did.

I tried configuring php.ini and set error reporting to just E_ALL just to see if PHP would "shut up". No luck.

Could you please help me understand why things such as $_SESSION, $_COOKIE, $_GET, $_POST, $_SERVER, and $_REQUEST are not working and why they are thought to be undefined indexes?

Thank you. Your answers are appreciated.

Re: XAMPP Undefined Index - $_SESSION, $_POST, $_GET, $_REQU

PostPosted: 29. January 2012 09:51
by Altrea
Hi Ricky,

  1. Your sourcecode doesn't fit to any of the two error messages
  2. I don't believe you didn't find anything about that two error messages. They are very common.

To prevent undefined index messages, proof your array keys with isset() or empty() before you use them. You have done this in your posted code.
Code: Select all
$key = $_SESSION['key'];

if( isset( $_SESSION['key'] ) ) {
    $key = $_SESSION['key'];

To prevent Use of undefined constant messages, put your array keys into single or double quotes. You have done that too in your posted sourcecode.
Code: Select all
echo $_SESSION[key];

echo $_SESSION['key'];

So, nothing more to do.

best wishes,