PeterPopper Posted November 21, 2009 Share Posted November 21, 2009 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 https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/ Share on other sites More sharing options...
cags Posted November 21, 2009 Share Posted November 21, 2009 If the number needs to go up 'globally', you will need to either user a database or store the value in a file and read/amend it from there using the file handling functions. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-962559 Share on other sites More sharing options...
abazoskib Posted November 21, 2009 Share Posted November 21, 2009 I would store it in a file. No point in wasting database calls. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-962577 Share on other sites More sharing options...
roopurt18 Posted November 21, 2009 Share Posted November 21, 2009 This is going to be chaos and inaccurate on a high traffic site. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-962616 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 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 https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-962627 Share on other sites More sharing options...
PeterPopper Posted November 22, 2009 Author Share Posted November 22, 2009 Is using the file option unwise? I am doing it because the client wants visitors to see how many other visitors have filled out the form. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963185 Share on other sites More sharing options...
KingIsulgard Posted November 22, 2009 Share Posted November 22, 2009 Yes it is unwise because it will give troubles when two people are updating the file at the same time. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963227 Share on other sites More sharing options...
roopurt18 Posted November 22, 2009 Share Posted November 22, 2009 Quote But I don't want to use a database. Where did this requirement come from? Your passing thoughts or the client? Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963308 Share on other sites More sharing options...
PeterPopper Posted November 22, 2009 Author Share Posted November 22, 2009 The client doesn't want to pay for the database work, but I think I will have to convince the client to use database. Thanks for all the replies. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963314 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 There is a third option. You could create an image and keep re-creating it and show it that way and use the file name as your counter....haha kinda simple and odd, but it would work. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963315 Share on other sites More sharing options...
abazoskib Posted November 22, 2009 Share Posted November 22, 2009 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 https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963319 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 Quote 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 https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963321 Share on other sites More sharing options...
PeterPopper Posted November 22, 2009 Author Share Posted November 22, 2009 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. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963324 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 Quote 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 https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963383 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 You can see an example here. http://www.kinggoddard.com/test2.php It isn't perfect, but it gets the job done. If you added a few more things to make sure all is well it would help. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963385 Share on other sites More sharing options...
PeterPopper Posted November 22, 2009 Author Share Posted November 22, 2009 Thank you very much for the examples, Cardale. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963459 Share on other sites More sharing options...
Cardale Posted November 22, 2009 Share Posted November 22, 2009 No problem. I will send you the bill later. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-963496 Share on other sites More sharing options...
PeterPopper Posted November 23, 2009 Author Share Posted November 23, 2009 Cardale, how can I show just the number without the background image? The number has to blend in with the rest of the design on the page. Thanks. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-964204 Share on other sites More sharing options...
Cardale Posted December 19, 2009 Share Posted December 19, 2009 I posted an update that works a lot better. Not that it is a huge deal or anything. http://www.kinggoddard.com/portfolio.php And to answer your question I put another piece of code to only display the number. Link to comment https://forums.phpfreaks.com/topic/182406-store-and-update-number-without-database/#findComment-980482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.