[wName][,wFeature][,wReplace])
The parameter page indicates the web page to be opened.
The parameter wName represents the name of the window to be opened, which can be attribute values such as _blank, _parent, etc., or can be a custom name.
The parameter wFeatures represents the style of the window to be opened.
The attribute values are as follows:
fullscreen: yes,no,1,0; Is it fullscreen
top: number; distance from the new window to the upper boundary
left: number; distance from the new window to the left border
width: number; width of new window
height: number; the height of the new window
location: yes,no,1,0; Whether to display the address bar
menubar: yes,no,1,0; Whether to display the menu bar
resizable: yes,no,1,0; Can it be changed in size?
scrollbars: yes,no,1,0; Whether to display scrollbars
status: yes,no,1,0; Whether to display status bar
toolbar: yes,no,1,0; Whether to display the toolbar
directories: yes,no,1,0; Whether to display the link
//Refresh is prohibited
<script language="javascript">
function enterkey(){
if( == 116){ //If the key is F5 key
alert('Refresh is prohibited'); //The warning box pops up
= 0; //Return the key to zero
return false;
}
}
</script>
=enterkey; // Assign the function to the onkeydown event
<script language="javascript">
//Right-click is prohibited
function mouseright(){
if(==2){
alert('right mouse button is prohibited');
return false;
}
}
=mouseright;
</script>
However, this method has a loophole. When the user right-clicks the mouse and the warning box pops up, the right-click does not release the right-click. Press Enter to close the warning window, and then release the right-click. This will still pop up.
The second method is to use the oncontextmenu event to call the returnValue property in the event object. The oncontextmenu event is when the user right-clicks the mouse, a menu pops up, and the returnValue property can cancel the event.
<body oncontextmenu==false>
6. Monitor the client browser
There is a function ignore_user_abort() in PHP. When the function is set to True, the page code will continue to be executed even if the PHP page is closed. ignore_user_abort(true);
The connection_aborted() function can monitor whether the client browser is disconnected. int connection_aborted(void), when the function returns True, it means that the client browser has been disconnected.
Use this function to automatically update the user list and delete the disconnected user.
<?php
define('PATH',dirname($_SERVER['SCRIPT_NAME'])); //Chat room directory
define('CHAT_NAME','PHP Chat Room'); //Chat Room Name
define("MESS", ""); //Chat information
define("PERSON", ""); //List of online people
define("RETIME",3); //Refresh time
define("LINE",11); //The number of rows displayed in the public window
define("PRLINE",5); //The number of rows displayed in the private chat window
define("MAX",50); //Chain room number limit
define("MAXTIME",600000); //The maximum time not to speak is milliseconds
define("WELCOME","<font color=blue>Welcome to".CHAT_NAME.", please abide by the chat room rules, do not refresh maliciously, and do not use uncivilized words.</font>"); //Welcome
?>
2. Public function file
(1) The chklogin() function checks whether the user's nickname is duplicated. The parameter $user is the nickname of the logged-in user. When the function returns True, the nickname is not available; when the return value is False, the nickname is available.
function chklogin($file,$user){
$boo = false;
if(file_exists($file)){
$userarr = file($file);
/* Determine whether the nickname is duplicated */
foreach($userarr as $value){ //Judge whether the nickname is duplicated
$tmparr = exploit('#',$value); //Use "#" as the separator to split the string
if($user == $tmparr[0]){ //If this user is included in the user array
$boo = true;
break;
}
}
}
return $boo;
}
(2) The addlogin() function writes the logged-in user nickname into the file. The saving format is: nickname #IP# gender, the parameter $file is the saved file address, $user is the user nickname, $ip is the login IP, and $sex represents the user gender.
function addlogin($file,$user,$ip,$sex){
$tmp = $user.'#'.$ip.'#'.$(13).chr(10); //chr(13) is a carriage return, Chr(10) is a newline character, and chr(32) is a space character
$fp = fopen($file,'a'); //Write method appends information at the end of the file
$boo = fwrite($fp,$tmp);
fclose($fp);
return $boo;
}
(3) The function of the storeuser() function is to store user information as an array. The format is "user name, user gender", and the parameter $file is the user list file.The code is as follows:
function storeuser($file){
$tmparr = file($file); //Write file contents to an array
$userarr = array(); //Create an array
foreach($tmparr as $value){ //Loop out the array content
$tmparr = exploit('#',$value); //Use # to split the string
$userarr[] = $tmparr[0].','.$tmparr[2]; //Save the username and user gender into the new array
}
return $userarr;
}
(4) The addmess() function writes the speech content into the file. The parameter $file is the saved file address, and $mess is the content to be saved
function addmess($file,$mess){
$fp = fopen($file,'a'); //Open the file in append form
$boo = fwrite($fp,$(13).chr(10)); //Write information into a file
fclose($fp);//Close the file
return boo;
}
(5) The function of the deluser() function is to delete the user. The parameter $file is the saved file address, and $user is the user to be deleted
function deluser($file,$user){
$tmparr = file($file); //Write file contents to an array
$rearr = array(); //Create an array
foreach($tmparr as $value){ //Loop out the array content
$tmp = exploit('#',$value); //Use # to split the string
if($tmp[0] != $user){ //If the user name in the variable is not equal to the current user
$rearr[] = $value;//Save this user information to a new array
}
}
$fp = fopen($file,'w+'); //Open the file in a write-only manner
foreach($rearr as $value){ //Loop array
fwrite($fp,$value); //Write the array content
}
fclose($fp);//Close the file
}
(6) The function of getRows() is to return the number of lines of the file, and the parameter $file is the file name
function getRows($file){
if(file_exists($file)){ //If the file exists
$fl = file($file); //Write the file to an array by line
return count($fl); //Find the array length and return
}else{
return 0; //If the file does not exist, return 0
}
}
download:Click to download the source code
The parameter page indicates the web page to be opened.
The parameter wName represents the name of the window to be opened, which can be attribute values such as _blank, _parent, etc., or can be a custom name.
The parameter wFeatures represents the style of the window to be opened.
The attribute values are as follows:
fullscreen: yes,no,1,0; Is it fullscreen
top: number; distance from the new window to the upper boundary
left: number; distance from the new window to the left border
width: number; width of new window
height: number; the height of the new window
location: yes,no,1,0; Whether to display the address bar
menubar: yes,no,1,0; Whether to display the menu bar
resizable: yes,no,1,0; Can it be changed in size?
scrollbars: yes,no,1,0; Whether to display scrollbars
status: yes,no,1,0; Whether to display status bar
toolbar: yes,no,1,0; Whether to display the toolbar
directories: yes,no,1,0; Whether to display the link
(2) Block <F5> key
The masking <F5> key is controlled by triggering the keyboard press event (onkeydown). When the user presses the key, the system judges the keyCode attribute in the event object. If it is the <F5> key, a warning box pops up and the key is set to 0. The key value of the <F5> key is 116.
Copy the codeThe code is as follows:
//Refresh is prohibited
<script language="javascript">
function enterkey(){
if( == 116){ //If the key is F5 key
alert('Refresh is prohibited'); //The warning box pops up
= 0; //Return the key to zero
return false;
}
}
</script>
=enterkey; // Assign the function to the onkeydown event
(3) Block the right mouse button
There are two ways to block the right mouse button. The first is to judge through attributes. If the button is equal to 2, it means that the right mouse button is pressed. This method is triggered by onmousedown time.
Copy the codeThe code is as follows:
<script language="javascript">
//Right-click is prohibited
function mouseright(){
if(==2){
alert('right mouse button is prohibited');
return false;
}
}
=mouseright;
</script>
However, this method has a loophole. When the user right-clicks the mouse and the warning box pops up, the right-click does not release the right-click. Press Enter to close the warning window, and then release the right-click. This will still pop up.
The second method is to use the oncontextmenu event to call the returnValue property in the event object. The oncontextmenu event is when the user right-clicks the mouse, a menu pops up, and the returnValue property can cancel the event.
Copy the codeThe code is as follows:
<body oncontextmenu==false>
6. Monitor the client browser
There is a function ignore_user_abort() in PHP. When the function is set to True, the page code will continue to be executed even if the PHP page is closed. ignore_user_abort(true);
The connection_aborted() function can monitor whether the client browser is disconnected. int connection_aborted(void), when the function returns True, it means that the client browser has been disconnected.
Use this function to automatically update the user list and delete the disconnected user.
2. Chat room
1. Configuration file
Copy the codeThe code is as follows:
<?php
define('PATH',dirname($_SERVER['SCRIPT_NAME'])); //Chat room directory
define('CHAT_NAME','PHP Chat Room'); //Chat Room Name
define("MESS", ""); //Chat information
define("PERSON", ""); //List of online people
define("RETIME",3); //Refresh time
define("LINE",11); //The number of rows displayed in the public window
define("PRLINE",5); //The number of rows displayed in the private chat window
define("MAX",50); //Chain room number limit
define("MAXTIME",600000); //The maximum time not to speak is milliseconds
define("WELCOME","<font color=blue>Welcome to".CHAT_NAME.", please abide by the chat room rules, do not refresh maliciously, and do not use uncivilized words.</font>"); //Welcome
?>
2. Public function file
(1) The chklogin() function checks whether the user's nickname is duplicated. The parameter $user is the nickname of the logged-in user. When the function returns True, the nickname is not available; when the return value is False, the nickname is available.
Copy the codeThe code is as follows:
function chklogin($file,$user){
$boo = false;
if(file_exists($file)){
$userarr = file($file);
/* Determine whether the nickname is duplicated */
foreach($userarr as $value){ //Judge whether the nickname is duplicated
$tmparr = exploit('#',$value); //Use "#" as the separator to split the string
if($user == $tmparr[0]){ //If this user is included in the user array
$boo = true;
break;
}
}
}
return $boo;
}
(2) The addlogin() function writes the logged-in user nickname into the file. The saving format is: nickname #IP# gender, the parameter $file is the saved file address, $user is the user nickname, $ip is the login IP, and $sex represents the user gender.
Copy the codeThe code is as follows:
function addlogin($file,$user,$ip,$sex){
$tmp = $user.'#'.$ip.'#'.$(13).chr(10); //chr(13) is a carriage return, Chr(10) is a newline character, and chr(32) is a space character
$fp = fopen($file,'a'); //Write method appends information at the end of the file
$boo = fwrite($fp,$tmp);
fclose($fp);
return $boo;
}
(3) The function of the storeuser() function is to store user information as an array. The format is "user name, user gender", and the parameter $file is the user list file.The code is as follows:
Copy the codeThe code is as follows:
function storeuser($file){
$tmparr = file($file); //Write file contents to an array
$userarr = array(); //Create an array
foreach($tmparr as $value){ //Loop out the array content
$tmparr = exploit('#',$value); //Use # to split the string
$userarr[] = $tmparr[0].','.$tmparr[2]; //Save the username and user gender into the new array
}
return $userarr;
}
(4) The addmess() function writes the speech content into the file. The parameter $file is the saved file address, and $mess is the content to be saved
Copy the codeThe code is as follows:
function addmess($file,$mess){
$fp = fopen($file,'a'); //Open the file in append form
$boo = fwrite($fp,$(13).chr(10)); //Write information into a file
fclose($fp);//Close the file
return boo;
}
(5) The function of the deluser() function is to delete the user. The parameter $file is the saved file address, and $user is the user to be deleted
Copy the codeThe code is as follows:
function deluser($file,$user){
$tmparr = file($file); //Write file contents to an array
$rearr = array(); //Create an array
foreach($tmparr as $value){ //Loop out the array content
$tmp = exploit('#',$value); //Use # to split the string
if($tmp[0] != $user){ //If the user name in the variable is not equal to the current user
$rearr[] = $value;//Save this user information to a new array
}
}
$fp = fopen($file,'w+'); //Open the file in a write-only manner
foreach($rearr as $value){ //Loop array
fwrite($fp,$value); //Write the array content
}
fclose($fp);//Close the file
}
(6) The function of getRows() is to return the number of lines of the file, and the parameter $file is the file name
Copy the codeThe code is as follows:
function getRows($file){
if(file_exists($file)){ //If the file exists
$fl = file($file); //Write the file to an array by line
return count($fl); //Find the array length and return
}else{
return 0; //If the file does not exist, return 0
}
}
download:Click to download the source code
Previous page12Read the full text