Link to home
Start Free TrialLog in
Avatar of loong
loong

asked on

PHP getting - PHP Notice: Use of undefined constant

Hello,

I am getting this error in our windows server 2008 environment.

PHP Notice:  Use of undefined constant act - assumed 'act' in C:\mydomain.com\admin\action.php on line 4
PHP Notice:  Undefined index:  act in C:\mydomain.com\admin\action.php on line 4

The script is as per attached. Anyone can help?
action.txt
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

How are you defining $r?  Is act defined as a constant in your code?  Otherwise if act is an index of an array, and not a constant, your code should read:
 
$act = $r['act'];

Open in new window

Avatar of loong
loong

ASKER

Well I am uncertain as this files have been move over from one site to another. Before it was move, the site is running. After moving to our new environment, that's what we get. The only difference we could see is that the previous PHP version was 5.25. and now it is 5.2.17.
The problem with code snippets is that they don't allow you to see the whole picture.  Do you know whether $r is defined in the inc/inc.php file?  Is there any code above the snippet you showed me?  It is kind of strange because two lines below the problem you redefine $r.
Try placing this code on line 3 and tell me if you see anything:

foreach($r as $key => $value) {
	echo "<script language='javascript'>alert('key = " . $key . ", value = " . $value . "');</script>";
}

Open in new window

Avatar of loong

ASKER

Under inc/inc.php

<?
session_start();
require_once("inc/connect.php");
require_once("inc/function.php");

$r=$_REQUEST;

?>

Avatar of loong

ASKER

The code I had attach as action.txt on my first mail
Avatar of loong

ASKER

Putting the code still the same error
PHP Notice:  Use of undefined constant act - assumed 'act' in C:\mydomain.com\admin\action.php on line 7
PHP Notice:  Undefined index:  act in C:\mydomain.com\admin\action.php on line 7

only changes are the line since I had place  the line.

The file that browsing and giving error is action.php which it should as per my previous attach action.txt. Something like that:-

<?php
require_once("inc/inc.php");
foreach($r as $key => $value) {
      echo "<script language='javascript'>alert('key = " . $key . ", value = " . $value . "');</script>";
}

$act = $r[act];
$time = time();
$r=$_REQUEST;

switch ($act)
{

Sheesh, you have a bunch of nested files above that code.  $r could be anywhere.

I see you placed my code, but did the alerts pop up when you ran it?  If so, what were the values of $r?
Avatar of loong

ASKER

no pops out. exactly similar error with out without your codes. :(

Actually still weird as why previously it was working on another server but not this time...hmm
Avatar of Dave Baldwin
I looked at the code that was posted and the first part is simply out of order.  This part:

$act = $r[act];
$time = time();
$r=$_REQUEST;

should be:

$time = time();
$r=$_REQUEST;
$act = $r['act'];

And there isn't a PHP function called 'redirect'.  It should be:

header("Location: pgh.php") ;

http://us.php.net/manual/en/function.header.php
No popups means that $r is not an array.  Are you sure you guys made no changes to the code?
Avatar of loong

ASKER

Still getting this error this time at line 6 which is $act = $r['act'];

PHP Notice:  Undefined index:  act in C:\mydomain.com\admin\action.php on line 6
Avatar of loong

ASKER

Yeah no changes as we just pulled the code and place it in the new server
Wait, $_REQUEST comes as a result of a form submission.  Where is your form?
Avatar of loong

ASKER

Its actually a login page

Maybe u try this -

http://124.150.143.162/admin/loginnew.php

putting in dummy login id and password and u will see the error
OK, I see that in your form there is no way to post an act index.  That could be your first problem.

Did you change the input form at all in your move?
Avatar of loong

ASKER

I had just bring over the latest file again to the new server. Still the same. Actual domain which yet to point is http://www.palaceofthegoldenhorses.com.my/admin/loginnew.php

We set that ip is to test the whole application before pointing.
ASKER CERTIFIED SOLUTION
Avatar of OmniUnlimited
OmniUnlimited
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loong

ASKER

Its ok we found the problem was due  to reporting error is not off..
I'm sorry, but turning error reporting off will not solve your problem, simply get rid of the annoyance of the warning message, but not resolve the error you have in your coding.

If you are saying that error reporting was off on your original site it may be that this code never worked.
Avatar of loong

ASKER

Yeah could be actually...Hmmmm
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of loong

ASKER

customer ok to turn off notice
To anyone reading this thread... Do not do what loong is doing here -- it is technically incompetent and potentially dangerous.  

You don't want to be that guy!