php - File name as variable+.txt -
session_start(); $user = $_session['username']; if( isset($_post['subm_btn']) ) { incrementclickcount(); } function getclickcount() { return (int)file_get_contents($user.".txt"); } function incrementclickcount() { $count = getclickcount() + 1; file_put_contents($user.".txt", $count); }
user register on site, click on button (name="subm_btn"). want count clicks , add number of clicks in file name "username.txt"
i guess looking this:
$file=$user.'.txt'; incrementclickcount($file); function incrementclickcount($file){ $count = getclickcount($file) + 1; file_put_contents($file, $count); } function getclickcount($file) { return (int)file_get_contents($file); }
if want variable available inside function either make global or pass argument (which better).
Comments
Post a Comment