CCount Custom ID's

Everything related to CCount PHP click counter
Post Reply
DC
Posts: 138
Joined: Sun Dec 09, 2007 9:28 am

CCount Custom ID's

Post by DC »

/*************************************

Title: CCount Custom ID's
Version: 1.0
Author: DC
Demo: None
Download: None
Website: http://www.clickcraft.net

Short description:
This mod will allow you to also add custom ID's as well as the stock scripts auto generated sequential ID's. I always felt that the abillity to add ones own custom ID's was a good one, so I created this little mod.

*************************************/

Lets Begin Our Mod, make sure you save a back up of the orig script incase any errors are made ...

Open index.php in your editor.
This should be txt based DO NOT USE anything like MS Word.

Look for the add function. as this is the func we will be modifying
function add() and replace the block of code that should look like this.

Code: Select all

$previd = file_get_contents($settings['idfile']);
$previd = trim($previd);
$previd++;

$fp = @fopen($settings['idfile'],'w') or error('Can\'t write to the IDs file ('.$settings['idfile'].')! Make sure PHP scripts have permission to write to this file (CHMOD it to 666 on LINUX machines!)');
flock($fp, LOCK_EX);
fputs($fp,$previd);
flock($fp, LOCK_UN);
fclose($fp);
With my mod code below.

Code: Select all

///////////////////////////////////////////////////
//DC Custom ID Mod 1.0 ...
///////////////////////////////////////////////////
$cust_id = trim(strip_tags($_POST['cust_id']));

if (preg_match("/[^0-9]/", $cust_id)) {
    error('Custom ID must be numeric ...');
}
$lines = file($settings['logfile']);

foreach ($lines as $thisline) {
$my_line = explode('%%',$thisline);
$previd  = rtrim($my_line[0]);
if ($cust_id != ''){
if (preg_match("/$cust_id/", $previd)){
    error('Custom ID already exists ...');
}
}
}
if ($cust_id == ''){
$previd = trim($previd);
$previd++;
}else{
$previd = $cust_id;
}
///////////////////////////////////////////////////
Now that we have replaced the stock func code we must now move on to the form section where we input the data. Look for the following block of code located around line 665.

Code: Select all

<tr>
<td>Start counting from:<sup>1</sup></td>
<td><input type="text" name="count" value="0" size="6"></td>
</tr>
Replace it with this block of code.

Code: Select all

<tr>
<td>Custom ID:</td>
<td><input type="text" name="cust_id" value="" size="6" maxlength="6">&nbsp;Leave blank for auto generated ID's ...</td>
</tr>

<tr>
<td colspan="2">&nbsp;</td>
</tr>

<tr>
<td>Start counting from:<sup>1</sup></td>
<td><input type="text" name="count" value="0" size="6"></td>
</tr>
That should complete our mod, and you can now save the file and test the mod.

Enjoy, DC
To Code Or Not To Code That Is The Question?

Was my post of any help to you? if so please do [url=http://www.clickcraft.net/slice_donations.php][b]Buy Me A Slice[/b][/url] ...
puniksem
Posts: 47
Joined: Thu Nov 01, 2007 12:25 pm

BIG problem with the script mod!

Post by puniksem »

I've implemented your script modifications and found that you may have over looked one small exception to an otherwise cool mod.

Once I generate my own custom ID for a new link, and then followed it with an auto generated link, the script generates a number sequential to the manually generated ID, and doesn't revert to the sequential auto generated ID. Even if I delete the manually generated ID the sequence continues from my manual input.

This error may be as a result of firefox browser caching, as I've also observed that id.txt didn't increment it's count when I added a custom ID.

PS. the second section of your mod replacement started at line 602, no wonder I had trouble finding it around line 665. LOL

PPS. Thanks, yes I was aware of the problems associated with non SQL data manipulations. I use this script to monitor no more than around 100 URL's and they are low traffic volumes too.

I hope this information helps any adjustments that may be required, I've subbed to this thread with interest.

I look forward to your reply.
World's shortest poem: We, see.
DC
Posts: 138
Joined: Sun Dec 09, 2007 9:28 am

Post by DC »

Actually nope I did that on purpose, I wanted it to work just like Klem wrote it to work but with the addition of being able to enter your own custom ID's, remember this can present a prob as well, so you may have noticed that I even run a check to make sure you do not try and use the same ID again.

The idea is you can enter the ID or it can count directly from the custom ID you have entered if you like. This is not somthing I over looked.

But I do thank you for the feed back. Feel free to mod my mod as it may still be a great strting point for your ideas.

You can of course generate any type of numeric ID you like with my mod now that it allows the script to do it, so half the battle has been won, you can try a nix time stamp if you like, that wouldn't be so simple to guess but as it is numeric it would work ... you can even gen time based MD5 if you want to get fancy but would need to mod the script a bit more to do so as I am following what Klem designed his script to do but with added features.

Ah your question on the ID's text file I do not use that at all in my mod so anything you have in there will be worthless I am going about this completely dif thus preventing the problems we would have with the file in use with custom ID's so you can actualy remove that file as im reading the data direct and using that instead.

But I like how you have been so observent, and I do welcome comments on my mods. some of my mods are acually in use by Klem in some of his scripts so I do run many of my ideas past him before I even post it here.

As for line numbers thats why I say around this line because my versions are highly modified, so my numbers can't ever match your virgin script this is just one of many mods that are in my mod test script ...

DC
To Code Or Not To Code That Is The Question?

Was my post of any help to you? if so please do [url=http://www.clickcraft.net/slice_donations.php][b]Buy Me A Slice[/b][/url] ...
Post Reply