chasebadkids Posted February 14, 2008 Share Posted February 14, 2008 Hey, I got this 3rd party "stats" script that I was wanting to use on my site, the code for the stats script is here: http://phpfi.com/296352 and this is my site where I'm using the code. http://itsmyipod.net/ check out my site and see all the errors I'm getting, any idea why Id be getting these? Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/ Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 It means you've tried to use year without actually having defined it define('year', 'value'); I'd assume this is because you haven't installed the script properly (which will be trying to use the constants). Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-466611 Share on other sites More sharing options...
KrisNz Posted February 14, 2008 Share Posted February 14, 2008 It's also often caused by trying to access a variable but without a dollar sign or trying to access a hash key without placing the key in quotes. <?php $foo = 'bar'; //ok echo foo; //undefined constant, common typo $hash = array('foo'=>'bar'); echo $hash['foo']; //ok echo $hash[foo]; //undefined constant, foo is a string ?> Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-466625 Share on other sites More sharing options...
aschk Posted February 14, 2008 Share Posted February 14, 2008 As KrisNz says it'll be to do with using constants inside arrays. e.g. echo $hash[foo]; Because PHP is a lenient language you're lucky, and because it doesn't recognise foo as a constant it instead converts it to a string for you, thus resolving your problem. Although you are still getting warnings probably because you turned them on. Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-466629 Share on other sites More sharing options...
chasebadkids Posted February 14, 2008 Author Share Posted February 14, 2008 I hate to sound like an idiot but I'll admit It's been a while since ive tackled php and im a bit rusty... I dont quite get what I need to do, can anyone tell me exactly what needs to be done or changed? or has another script thta works the same way? Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467093 Share on other sites More sharing options...
PHP Monkeh Posted February 14, 2008 Share Posted February 14, 2008 Change these values at line 6: $today = getdate(); $month = $today[month]; $mday = $today[mday]; $year = $today[year]; to $today = getdate(); $month = $today['month']; $mday = $today['mday']; $year = $today['year']; Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467095 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 This is going to make a couple people on this forum yell at me but... If you find there are lot's of these Notice errors, just turn Notices off for error_reporting: http://us.php.net/error-reporting. Notices are off by default in PHP, and if you didn't write the code, it's *usually* not worth the hassle of trying to fix someone else's poor coding. As long as the site works as expected with them off.... Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467100 Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 But whenever you use $x[a] instead of $x['a'] (especially in a loop) the php interpreter looks for a constant "a" definition, and, when it can't find one, decides to treat it as "a". Even with notices "off" you are still wasting processing time. Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467105 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 I agree...but if I have a 3rd party product, I'm not going to go through all their files looking for their mistakes. Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467107 Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 If they're that flaky I hope you don't use them for anything mission-critical Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467113 Share on other sites More sharing options...
PFMaBiSmAd Posted February 14, 2008 Share Posted February 14, 2008 I'm with Barand. If a publicly released script was not written with enough care or by someone with enough programming experience to use correct syntax, then just think of all the other problems that could be present in it that would allow code/sql/email injection or un-caught validation and error checking that will either display errors to the visitor or result in broken or blank pages. Using $today[month] vs $today['month'] is just basic abc123 syntax, it is not even programming logic. Could the actual program logic be worth much? Quote Link to comment https://forums.phpfreaks.com/topic/91037-notice-use-of-undefined-constant-what-does-this-mean/#findComment-467179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.