Jump to content

Recommended Posts

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?

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).

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
?>

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.

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?

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'];

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....

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.

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.