`Hello guys im trying to make this php code;

if(file_exists("u/txt/Chat/logged.txt")){
	$file = $_SERVER[PHP_SELF];
	if($file=="/systemchat.php"){
	$file = file_get_contents("u/txt/Chat/logged.txt");
	
	if(!strpos($file, $username)) {
	$myFile = "u/txt/Chat/logged.txt";
	$fh = fopen($myFile, 'a+') or die("Can't open file");
	$stringData = '<b>'.$username.'</b><br/>';
	fwrite($fh, $stringData);
	fclose($fh);
	
	}
}

refreshed every second with Ajax, wondering how i should do that, havent had time to learn ajax :/

try using the following script, with the GET file pointing to your file and adjusting the refresh rate to whatever you need. I just took the from an online tutorial. easy to get started

<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.