[Done v1.5.3] PHP Warning: Couldn't find constant in admin_access.php
I set up my first Zen Cart this October and thought everything was running pretty smoothly, but just looked in the "logs" folder and see about 11,000 identical messages. Example of a file name is myDEBUG-adm-1354337184-103753.log. The messages started about 17 days ago and all look like this except it's repeated 4 times:
[30-Nov-2012 21:41:11] PHP Warning: constant() [<a href='function.constant'>function.constant</a>]: Couldn't find constant in /home/content/24/XXXXXXX/html/MY_CART/adminXXXXXX/includes/functions/admin_access.php on line 38
I checked in /MY_CART/adminXXXXXX/includes/functions/admin_access.php and this is what it says on line 38:
if (constant($result->fields['main_page']) == $page && $result->fields['page_params'] == $page_params) {
If anyone can explain what is happening and how to fix this it would be much appreciated.
Thanks, Ed
Re: myDEBUG-adm log files - question
What plugin did you install on the day that those messages started appearing?
Re: myDEBUG-adm log files - question
Thanks for the quick reply DrByte.
Am pretty sure that no plugins were installed on or around that date. Believe the last plugin added was Edit Orders back in October/early November-am trying to add as little as possible until I set up a test cart.
I did add a second Admin user but thought that was more recently- in December and the myDebug messages started on Nov. 30th. I was thinking about deleting that Admin username and seeing if anything changed with the error messages but figured I would ask here first in case there was a known issue and simple solution. Any suggestions very much appreciated.
Re: myDEBUG-adm log files - question
I suppose it could be related to things the second user is doing. But if that's the case, deleting the user and recreating won't solve the problem.
Can you list all the plugins/addons you've installed? I'm mainly interested in the ones that would need/try to add anything to the admin menu.
I've seen others post a similar error message, but was never able to reproduce the symptoms in order to test anything. Most puzzling. But more information about your setup can't hurt.
Re: myDEBUG-adm log files - question
OK, am 99% sure I have tracked down and solved the problem.
My new Admin username was an email address - [email protected] . I had a specific reason for using an email address for my new Admin username- but since it cause issues am just going to delete it and make a new Admin. I checked my logs folder in almost real time when logging in and out and using Who's Online. The myDebug errors only showed up when I used the Admin with the email address username.
I assume you are not supposed to use special characters like "@" and "." in username because they can cause errors like what occurred here- never looked into it because it seemed to be working OK. Live and learn, glad it was something simple. Thanks for the responses.
Ed
Re: myDEBUG-adm log files - question
Hmmm ... While I've never used an @ symbol in an admin username, I can't think of any reason why that would cause a problem. Will have to test that sometime.
But if that's what fixes it for you, that's great news.
Re: myDEBUG-adm log files - question
After some more testing it appears that any Administrator account creates the myDebug errors when logged in. A Superuser account does not. I created another Administrator account with a normal username and got a couple errors a minute.
So I upgraded the Administrator account with email address for username to Superuser account and no errors. The "@" character was not the problem.
I am currently the only user of the site and mainly created extra Admin accounts in case I couldn't log in for some reason- want to have two other usernames/passwords just in case. Are there any potential problems to making the accounts Superusers instead of Administrators? Would still like to solve the issue in case I ever want to give someone else limited access to site as Administrator.
Using Cherry Zen template. My Plug Ins are Image Handler, Zen Lightbox, Edit Orders, Easy Populate, and Keepalive Timer. I think that's it.
Re: myDEBUG-adm log files - question
Quote:
Originally Posted by
EdsGoodStuff
Are there any potential problems to making the accounts Superusers instead of Administrators?
No, that's fine, as long as they have secure passwords.
Re: myDEBUG-adm log files - question
Seem to have found a solution.
I went to Admin Access Management> Admin Profiles and clicked on Edit for the Administrator User Profile. The BOX_HEADING_PRODUCT_TYPES category at the bottom of the page has four check-boxes of which three were checked by default- Product-Music, Document-General, and Document-Product. When I uncheck these boxes and update the profile I can log in as Administrator and not get any myDebug errors.
Re: myDEBUG-adm log files - question
Thanks. We'll dig into it.
Did your site start out as v1.5.1, or is it an upgrade from a prior version?
Re: myDEBUG-adm log files - question
Re: myDEBUG-adm log files - question
I've traced this down to the following conditions:
- The currently signed-in admin is not a superuser.
- The admin profile associated with that admin has one or more of the 'Product Types' enabled.
For that set of conditions, the check_page function in admin_access.php is choking on the (non-existent) constant associated with the enabled Product Type. In that case, the main_page value returned for the enabled product type by the SQL query at line 29 of /ADMIN/includes/functions/admin_access.php is empty because there's no such key (e.g. _productTypes_product_music) to associate.
With the changes in red, the debug logs no longer are created ... but I'm not sure if (a) it's an appropriate change and (b) if it's a complete change.
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:";
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
$pageName = zen_not_null($result->fields['main_page']) ? constant($result->fields['main_page']) : '';
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
I also noticed during my "playing" with this that it's not possible to check 'Product Types', 'Product - Free Shipping' in an admin profile and have it remain checked after clicking the Update button.
Re: myDEBUG-adm log files - question
Quote:
Originally Posted by
lat9
I also noticed during my "playing" with this that it's not possible to check 'Product Types', 'Product - Free Shipping' in an admin profile and have it remain checked after clicking the Update button.
The issue here is that the page_key value created in the admin_pages_to_profiles table (_productTypes_product_free_shipping) is 35 characters long and doesn't quite fit into the field that's defined as varchar(32).:(
Re: myDEBUG-adm log files - question
Quote:
Originally Posted by
lat9
With the changes in
red, the debug logs no longer are created ... but I'm not sure if (a) it's an appropriate change and (b) if it's a complete change.
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:";
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
$pageName = zen_not_null($result->fields['main_page']) ? constant($result->fields['main_page']) : '';
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
A better solution is to improve the query to 'weed out' the erroneous selection in the first place:
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:
AND ap2p.page_key NOT LIKE '_productTypes_%'";
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
$pageName = constant($result->fields['main_page']);
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
Re: myDEBUG-adm log files - question
Quote:
Originally Posted by
EdsGoodStuff
[30-Nov-2012 21:41:11] PHP Warning: constant() [function.constant]: Couldn't find constant in /home/content/html/admin/includes/functions/admin_access.php on line 38
I checked in /admin/includes/functions/admin_access.php and this is what it says on line 38:
if (constant($result->fields['main_page']) == $page && $result->fields['page_params'] == $page_params) {
Quote:
Originally Posted by
EdsGoodStuff
Seem to have found a solution.
I went to Admin Access Management> Admin Profiles and clicked on Edit for the Administrator User Profile. The BOX_HEADING_PRODUCT_TYPES category at the bottom of the page has four check-boxes of which three were checked by default- Product-Music, Document-General, and Document-Product. When I uncheck these boxes and update the profile I can log in as Administrator and not get any myDebug errors.
Quote:
Originally Posted by
lat9
I've traced this down to the following conditions:
- The currently signed-in admin is not a superuser.
- The admin profile associated with that admin has one or more of the 'Product Types' enabled.
For that set of conditions, the check_page function in admin_access.php is choking on the (non-existent) constant associated with the enabled Product Type. In that case, the main_page value returned for the enabled product type by the SQL query at line 29 of /ADMIN/includes/functions/admin_access.php is empty because there's no such key (e.g. _productTypes_product_music) to associate.
With the changes in
red, the debug logs no longer are created ... but I'm not sure if (a) it's an appropriate change and (b) if it's a complete change.
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:";
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
/// FIX: add the zen_not_null() check here
$pageName = zen_not_null($result->fields['main_page']) ? constant($result->fields['main_page']) : '';
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
I also noticed during my "playing" with this that it's not possible to check 'Product Types', 'Product - Free Shipping' in an admin profile and have it remain checked after clicking the Update button.
Quote:
Originally Posted by
lat9
The issue here is that the page_key value created in the admin_pages_to_profiles table (_productTypes_product_free_shipping) is 35 characters long and doesn't quite fit into the field that's defined as varchar(32).:(
Quote:
Originally Posted by
lat9
A better solution is to improve the query to 'weed out' the erroneous selection in the first place:
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:
AND ap2p.page_key NOT LIKE '_productTypes_%'";
/// FIX: added the AND line above
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
$pageName = constant($result->fields['main_page']);
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
Moved to Bug Reports area for further investigation.
Re: myDEBUG-adm log files - question
I just wanted to report that I experienced this bug as well. Mine is a heavily modified zen cart that has been updated from 1.3.8 to it's current 1.5.1. Some plugins that might have triggered this? Perhaps SSU or the fact that I had previously installed admin profiles, but then removed it once I upgraded to 1.5.1.
Once I went in and set up profiles for everyone the error seemed to disappear and hasn't come back. So I'm just hoping it was temporary and ignoring it for now.
Re: myDEBUG-adm log files - question
Same problem here in fresh install of 1.5.1 No mods or edits its stock u Get the following message: PHP Warning: constant(): Couldn't find constant in /..includes/functions/admin_access.php on line 38, referer: http://.../categories.php?cPath=11&c...=edit_category
An 8mb error log file has been growing and growing because of this error. Is there a fix? I tried the above and i get an "Error please refresh this page" when trying to edit categories.
The problem also does not occur on superuser profile. Only occurs on custom profiles.
Re: myDEBUG-adm log files - question
I've got this issue with other than super user profiles AFTER installing Image Handler 4, but people in the IH thread concluded that it would not be an IH problem. So, the problem really persists and an administrator can't update the product info anymore due to this permission issue:
http://www.zen-cart.com/showthread.p...36#post1189336
The error log tells about the same CONSTANT issues than in this thread.
Re: myDEBUG-adm log files - question
Quote:
Originally Posted by
lat9
A better solution is to improve the query to 'weed out' the erroneous selection in the first place:
Code:
$sql = "SELECT ap.main_page, ap.page_params
FROM " . TABLE_ADMIN . " a
LEFT JOIN " . TABLE_ADMIN_PAGES_TO_PROFILES . " ap2p ON ap2p.profile_id = a.admin_profile
LEFT JOIN " . TABLE_ADMIN_PAGES . " ap ON ap.page_key = ap2p.page_key
WHERE admin_id = :adminId:
AND ap2p.page_key NOT LIKE '_productTypes_%'";
$sql = $db->bindVars($sql, ':adminId:', $_SESSION['admin_id'], 'integer');
$result = $db->Execute($sql);
$retVal = FALSE;
while (!$result->EOF) {
$pageName = constant($result->fields['main_page']);
if (($pageName == $page || basename($pageName, '.php') == $page) && $result->fields['page_params'] == $page_params) {
$retVal = TRUE;
}
$result->MoveNext();
}
I've been using this fix on a couple of my 1.5.1 installations since January 2013 and it appears to work well. Thanks lat9!