Failing to write all data to file
Posted by dabbler (dabbler), 30 May 2003Hi Graham.
After 3 hours of picking through code and the php manual, I am stuck. Please forgive me if this post is not in following with the intended nature of this forum. It's my last resort. I'd greatly appreciate a little help with this.
I have a set of scripts that run a banner management system. It's great but for one problem that is making unusable. It looks to me like it could be something simple that I just don't know enough to see. Or it's something to do with having an NT server that requires some small change.
Ads.dat holds all of the data for the scripts, the configuration data, and the ad data. When using the admin area, saving the config changes writes to file as it should. The problem is when the ad data (specifically clickthrus) changes and the file is rewritten, it omits the config data. I think I've narrowed it down to two smaller problem areas.
Click.php, which logs the click and redirects
And then in ads.inc.php
Is there an obvious error here? Everything is fine until a click, and it logs the click. Just loses the $key and $val data somehow. Any help would be greatly appreciated.
Posted by admin (Graham Ellis), 30 May 2003Hi ... welcome ... and exactly the right use of the forum ... interesting problem too.
Educated guess: add the line
before the while (....) line in the writeads function.
In PHP, the each function returns a key / value pair from an array each time you call it, and it returns a false value when it runs out of data. So far, so good ... except that when you enter such a loop it starts from wherever it happened to reach last time you used each on the same array last. The frighteningly named "reset" simply resets the internal pointer that each uses so that it starts (again) at the beginning. There are time where you have to do a reset before a loop of each-es, even if you've never eached through the array before. I don't think the pointer is automatically initislised when an array is created.
Anyhow - if that's it, great ... if not, let me know and I'll have a further look (I would probably end up suggesting creating an extra temporary file to write variable into to see more about where the failure is occurring ....)
Posted by dabbler (dabbler), 30 May 2003Ahhhh, and fantastic, that did the trick.
Thank you. Now everything keeps displaying properly.
It never fails that when I pick up a free script, I have to spend time customizing it to make it work for me the way I'd like, which has been good, I've learned a lot this way.
Thanks again, you're a star.
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho