Jump to content
xisto Community
Sign in to follow this  
nightfox1405241487

Logging Items Entered Into A Textbox

Recommended Posts

I'd like to have a log of items entered into a search box on my site. How can I do this so it will write to a text file but not interfear with search operations?

 

Thanks!

 

[N]F

1064336422[/snapback]


Depends on your script.

Basically, the script that actually performs the search functions would need to be modified slightly.

 

At the begining of that script, you would need to open your log file, write the vriable (search term) to it, close the log file then continue as normal.

 

$_POST['search'] should be the the way to gather you search term. This means the post method form field named 'search'. :)

 

You'll need to se the file system functions for PHP to open, modify, and close your log file.

 

For a little more effort, I suggest a table in your mySQL database that can track the terms used as well as the number of times the term was searched for.

 

Even better, break the search term up into seperate words (if a phrase was used) and add each word to the database and exclude common words like "the" "and" etc...

 

I'd need to know how much PHP you knew before I'd really get into the modification with you. For me, the general directions above would be enough but many people simply don't know any PHP so the directions above wouldn't be enough.

 

vujsa

Share this post


Link to post
Share on other sites

Come on! That's so simple!
Just place it to your search.php file

<?php   //$word is the word user inputs   if($word) {	  $fp=fopen("words.txt", "a");	   fwrite($fp, "$word|");	   fclose($fp);   }?>

As for counter of words:
<?php   $fp=fopen("words.txt", "r");   $words="";   while(!feof($fp)) {	  $words.=fread($fp, 1000);   }   $words=explode("|",$words);   for(i=0;i<sizeof($words);i++) {	$ma=0;	$ch=$words[i];	for(j=0;j<sizeof($words);j++) {	  if($ch==$let[j]) {	$ma++;	break;	  }	}	if($ma==0) {	  printf("Word %s is searched",$ch);	  $searched=0;	  for(j=0;j<strlen(word);j++) {	if($words[j]==$ch) {	  $searched++;	}	  }	  printf("%d times",$searched);	  $let[$t]=$ch;	  $t++;	}  }?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.