Hi im a beginner with php and also a new member of this site.
I am getting this error:
Warning: Cannot modify header information - headers already sent by (output started at /home/blake/public_html/searchsrc/google.php:4) in /home/blake/public_html/searchsrc/google.php on line 35
Also I would like to know how to make the first write (lastsearch.txt) overwrite everything in the file instead of just putting it next to it
Heres my code:
[php]
<?
if (!$_POST['search']) {
?>
<form method="post">
Search:
<input type="text" name="search"/>
<input type="submit" />
</form>
<?
}
else {
?>
<?php
$myFile = "lastsearch.txt";
$fh = fopen($myFile, 'r');
$tosearch = fread($fh, 5);
fclose($fh);
$search = $_POST['search'];
$file = "lastsearch.txt";
$filename = fopen($file, 'a') or die("can't open file");
fwrite($filename, $search."\r");
fclose($filename);
$ip= $_SERVER['REMOTE_ADDR'];
$search = $_POST['search'];
$file = "searchlog.txt";
$filename = fopen($file, 'a') or die("can't open file");
$date = date('j/n/y h:i:S A');
fwrite($filename, $ip." - ".$date." - ".$search."\r\n");
fclose($filename);
header("Location: http://google.com/search?q=$tosearch");
}
?>
[/php]
Thanks