Reputation:
I want my variable $code
to be incremented by 1 everytime, the php script is called. This is my code:
script.php:
<?php
$code = "05000"; /*On first run, the $code will be "05000",
then on second run it will be "05001" and so on and so forth*/
?>
Or in other words, I want my $code
to give a unique value (which should be self incrementing) everytime, the script is called. How can I do that?
Upvotes: 1
Views: 681
Reputation: 11
Store it in a simple file, you can use this ($count = $code for you) :
<?php
$storageFile = "storage.txt";
if (!file_exists($storageFile))
{
file_put_contents($storageFile, "0");
}
$count = file_get_contents($storageFile);
file_put_contents($storageFile, ($count + 1));
Upvotes: 1