Jump to content

store and update number without database


PeterPopper

Recommended Posts

I have a PHP  web form; every time a user submits the form, I want to display and update the number (like a counter) on the web page. This is for users to see how may people have submitted the form. But I don't want to use a database.

 

I want to have: This form was submitted 20 times, and keep updating the number each time the form is submitted.

 

Thanks.

Link to comment
Share on other sites

Firstly; why are you doing this? Are you trying to prove that you can? If you do follow through with this and store the number in a file, you're going to have to make sure that you lock the file in question while you're updating it, as you don't want two updates happening concurrently. But I have to say that I just don't see the point in what you're doing.

Link to comment
Share on other sites

There a lot of solutions to the problem. Another easy one, is to create a blank file somewhere on your server each time the submit button is pressed.  Then use something like shell_exec() to run "ls $fullpath_to_dir | wc -l" which will give you the number of files in that directory. I'm not saying this is the best method, but a database is really not required for such a task, especially since its the only thing you want to track.

Link to comment
Share on other sites

There a lot of solutions to the problem. Another easy one, is to create a blank file somewhere on your server each time the submit button is pressed.  Then use something like shell_exec() to run "ls $fullpath_to_dir | wc -l" which will give you the number of files in that directory. I'm not saying this is the best method, but a database is really not required for such a task, especially since its the only thing you want to track.

 

Thought of that one to...good one.

Link to comment
Share on other sites

I don't like the option to make a file for each count, eventually there will be hundreds, if not thousands, of empty files on the server.

 

Cardale, could you provide an example of the image example, that sounds promising.

 

Well honestly you wouldn't have thousands if you deleted the one before it, but in order to do this you have to create two files.

 

We will name this image.php

<?php
session_start();
$command = "find /var/www/test/*.jpg";
$file = exec($command);

$info = pathinfo($file);
$file_name =  basename($file,'.'.$info['extension']);

$realstring = $file_name;
$useimage  = imagecreatefromjpeg($file);
$linecolor = imagecolorallocate($useimage,233,239,239);
$textcolor = imagecolorallocate($useimage, 255, 255, 255);

imageline($useimage,1,1,40,40,$linecolor);
imageline($useimage,1,100,60,0,$linecolor);
imagestring($useimage, 5, 20, 10, $realstring, $textcolor);

header("Content-type: image/jpeg");

imagejpeg($useimage);

$_SESSION['filename'] = $file;
$_SESSION['file'] = $file_name;
?>

 

second example.php

<?php
session_start();
?>
<img src="test.php">
<?php
$file = $_SESSION['filename'];
$file_name = $_SESSION['file'];

$file_name = $file_name + 1;

rename("$file", "/var/www/test/".$file_name.".jpg");

?>

 

Now create a directory name it "test" give it proper permissions.  Then get a good image to use and name it 0.jpg. and that should be it after you set all the permissions correctly.

 

Hahah..cool

Link to comment
Share on other sites

  • 4 weeks later...
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.