Online Game Practice Summary (1), _php tutorial

Source: Internet
Author: User
Tags ereg mysql query

Online Games Exercise Summary (1),


The recent period of time in school also free to do nothing, anyway is a good long time, simply do a "Chinese chess" online games to kill time to play. After a long time did not write summary, and the whole process encountered problems, today hurriedly write a ha, inevitably behind will forget.

First, registration Login interface:

May say such a simple game, there may be many examples on the Internet, there is no need to register such a function, in fact, I just learn to play ha.

About registration I use PHP and as3.0 Interactive, there is very shallow with PHP, but also encountered a lot of problems:

1. Check whether the registration is successful: This also sleepy time is not very long, but feel more important, I searched some information to find:

The mysql_affected_rows ()//function returns the number of record rows affected by the previous MySQL operation. If the execution succeeds, the number of rows affected is returned, and if the last query fails, the function returns-1.

2. Mailbox Activation Verification:

 debug = FALSE; $this->smtp_port = $smtp _port; $this->relay_host = $relay _host; $this->time_out = 30; is used in Fsockopen () # $this->auth = $auth;//auth$this->user = $user; $this->pass = $pass; # $this->host_ name = "localhost"; is used in HELO command $this->log_file = ""; $this->sock = FALSE;} /* Main Function */function sendmail ($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $BCC = "", $additional _he Aders = "") {$mail _from = $this->get_address ($this->strip_comment ($from)); $body = Ereg_replace ("(^| ( \ \ \)] (\) "," \1.\3 ", $body); $header =" mime-version:1.0\r\n "; if ($mailtype = =" HTML ") {$header. =" content-type:text/ Html\r\n ";} $header. = "To:". $to. " \ r \ n ";" if ($cc! = "") {$header. = "cc:". $cc. " \ r \ n ";} $header. = "From: $from <". $from. " >\r\n "; $header. =" Subject: "$subject." \ r \ n "; $header. = $additional _headers; $header. =" Date: ". Date (" R ")." \ r \ n "; $header. =" X-mailer:by Redhat (php/". Phpversion ().") \ r \ n "; list ($msec, $sec) = Explode (" ", Microtime (); $header. = "Message-id: <". Date ("Ymdhis", $sec). ".". ($msec *1000000). ".". $mail _from. " >\r\n "; $TO = Explode (", ", $this->strip_comment ($to)), if ($cc! =" ") {$TO = Array_merge ($TO, Explode (", ", $this, Strip_comment ($CC)));} if ($bcc! = "") {$TO = Array_merge ($TO, Explode (",", $this->strip_comment ($BCC)));} $sent = True;foreach ($TO as $rcpt _to) {$rcpt _to = $this->get_address ($rcpt _to); $this->smtp_sockopen ($rcpt _ To) {$this->log_write ("Error:cannot send e-mail to". $rcpt _to. " \ n "); $sent = False;continue;} if ($this->smtp_send ($this->host_name, $mail _from, $rcpt _to, $header, $body)) {$this->log_write ("e-Mail has been sent to < ". $rcpt _to." >\n ");} else {$this->log_write ("Error:cannot Send email to <". $rcpt _to. " >\n "); $sent = FALSE;} Fclose ($this->sock); $this->log_write ("Disconnected from remote host\n");} return $sent;} /* Private Functions */function smtp_send ($helo, $from, $to, $header, $body = "") {if (! $this->smtp_putcmd ("Helo", $helo) {return $this->smtp_error ("Sending HELO command");} #authif ($this->auth) {if (! $this->smtp_putcmd ("Auth LOGIN", Base64_encode ($this->user))) {return $this Smtp_error ("Sending HELO command");} if (! $this->smtp_putcmd ("", Base64_encode ($this->pass)) {return $this->smtp_error ("Sending HELO command");}} #if (! $this->smtp_putcmd ("MAIL", "from:<". $from. " > ") {return $this->smtp_error (" Sending MAIL from command ");} if (! $this->smtp_putcmd ("RCPT", "to:<". $to. " > ") {return $this->smtp_error (" Sending RCPT to Command ");} if (! $this->smtp_putcmd ("data")) {return $this->smtp_error ("Sending data Command");} if (! $this->smtp_message ($header, $body)) {return $this->smtp_error ("Sending message");}  if (! $this->smtp_eom ()) {return $this->smtp_error ("Sending
 
  
   
. 
   
    
     
 [EOM] ");} if (! $this->smtp_putcmd ("Quit")) {return $this->smtp_error ("Sending quit Command");} return TRUE;} function Smtp_sockopen ($address) {if ($this->relay_host = = "") {return $this->smtp_sockopen_mx ($address);} else {return $this->smtp_sockopen_relay ();}} function Smtp_sockopen_relay () {$this->log_write ("Trying to". $this->relay_host. ":". $this->smtp_port. " \ n "); $this->sock = @fsockopen ($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); ! ($this->sock && $this-&GT;SMTP_OK ())) {$this->log_write ("Error:cannot connenct to relay host". $this->relay_host. " \ n "); $this->log_write (" Error: ". $errstr." (". $errno.") \ n "); return FALSE;} $this->log_write ("Connected to relay Host". $this->relay_host. " \ n "); return TRUE;;} function Smtp_sockopen_mx ($address) {$domain = Ereg_replace ("^.+@ ([^@]+) $", "\1", $address); @getmxrr ($domain, $ mxhosts) {$this->log_write ("error:cannot resolve MX \" ". $domain.") \ "\ n"); return FalsC;; foreach ($MXHOSTS as $host) {$this->log_write ("Trying to". $host. ":". $this->smtp_port. " \ n "); $this->sock = @fsockopen ($host, $this->smtp_port, $errno, $errstr, $this->time_out); $this->sock && $this->smtp_ok ()) {$this->log_write ("Warning:cannot Connect to MX host". $host. " \ n "); $this->log_write (" Error: ". $errstr." (". $errno.") \ n "); continue;} $this->log_write ("Connected to MX host". $host. " \ n "); return TRUE;} $this->log_write ("Error:cannot connect to any MX hosts (". Implode (",", $MXHOSTS). ") \ n "); return FALSE;} function Smtp_message ($header, $body) {fputs ($this->sock, $header. " \ r \ n ". $body); $this->smtp_debug (" > ". Str_replace (" \ r \ n "," \ n "). > ", $header." \n> ". $body." \n> ")); return TRUE;} function Smtp_eom () {fputs ($this->sock, "\r\n.\r\n"), $this->smtp_debug (". [eom]\n]; return $this-&GT;SMTP_OK ();} function Smtp_ok () {$response = Str_replace ("\ r \ n", "", Fgets ($this->sock)), $this->smtp_debug ($response. " \ n "); if (!erEg ("^[23]", $response)) {fputs ($this->sock, "quit\r\n"), Fgets ($this->sock,); $this->log_write ("Error: Remote host returned \ "". $response. " \ "\ n"); return FALSE;} return TRUE;} function Smtp_putcmd ($cmd, $arg = "") {if ($arg! = "") {if ($cmd = = ") $cmd = $arg; else $cmd = $cmd." ". $arg;} Fputs ($this->sock, $cmd. " \ r \ n "), $this->smtp_debug (" > ". $cmd." \ n "); return $this-&GT;SMTP_OK ();} function Smtp_error ($string) {$this->log_write ("Error:error occurred while". $string. ". \ n "); return FALSE;} function Log_write ($message) {$this->smtp_debug ($message), if ($this->log_file = = "") {return TRUE;} $message = Date ("M D h:i:s"). Get_current_user (). " [". Getmypid ()."]: ". $message; if (! @file_exists ($this->log_file) | |! ($fp = @fopen ($this->log_file, "a"))) {$this->smtp_debug ("warning:cannot open log file \" ". $this->log_file." \ "\ n"); return FALSE;;} Flock ($FP, LOCK_EX); Fputs ($fp, $message); fclose ($fp); return TRUE;} function Strip_comment ($address) {$comment = "\ ([^ ()]*\)" while (ereg ($comment, $address)) {$address = Ereg_replace ($comment, "", $address);} return $address;} function Get_address ($address) {$address = Ereg_replace ("([\t\r\n]) +", "", $address); $address = Ereg_replace ("^.*< ( . +) >.*$ "," \1 ", $address); return $address;} function Smtp_debug ($message) {if ($this->debug) {echo $message;}}}? >
    
   
  
 

This need to configure the SMTP service, now QQ mailbox NetEase mailbox can go to set up, and then as a proxy mailbox.

$SMTP = new SMTP ($smtpserver, $smtpserverport, True, $smtpuser, $smtppass);
$SMTP->debug = false;//off debugging
$state = $smtp->sendmail ($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);

A variable is used during the entire database operation to monitor whether an operation error occurred and to return the registration success;

Error_reporting (E_error | e_warning | E_parse);//Block all error warnings, etc.

Activation page:

 PhpHeader("Content-type:text/html;charset=utf-8"); require_once"Sendemail/mysqlinfo/sqlinfo.php"; $name=Base64_decode($_get[' ISDHF ']); if($name=="")      {          Exit(); }Else{                     $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD) or die(' Connection error '); //Select Database       mysql_select_db(Db_name,$con) or die(' occured error '); mysql_query(' SET NAMES UTF8 ') or die(' Show error '); $sql= "Select isactivated from chinesechess WHERE nickname= ' {$name}'"; //$row = @mysql_query ($query) or Die (' error ');        $result=mysql_query($sql,$con) or die(' ERROR '); //Close the database        $arr=Mysql_fetch_array($result); if($arr[' isactivated ']== ' 0 ')        {          //If there is no activation, the output activates the page, otherwise the webpage does not exist;Echo'
 
   
 
   Game registration [Welcome registration]      
 
   
 

Account activation

Your random nickname is:"'. $name. ' "

'; }Else { Echo"The page does not exist"; } Mysql_close(); }?>
 PhpHeader("Content-type:text/html;charset=utf-8"); require_once"Sendemail/mysqlinfo/sqlinfo.php"; error_reporting(E_error|e_warning|E_parse);//disable display of false sirens, etc.          $name=$_get[' Key ']; if($name=="")    {        Exit(); }Else    {       $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD) or die(' Connection error '); //Select Database       mysql_select_db(Db_name,$con) or die(' occured error '); mysql_query(' SET NAMES UTF8 ') or die(' Show error '); $sql= "UPDATE chinesechess SET isactivated= ' 1 ' WHERE nickname= ' {$name}'"; $result=mysql_query($sql,$con) or die(' ERROR '); //Close the database    Mysql_close(); Echo'            
 
           Account is activated        
 
   '; $name="        "; Echo'           
 
   
 

The account is activated

Your random nickname is:'. $name. '

Your account has been activated, I wish you a happy game!

'; }?>

Css:

@charset "Utf-8";/*CSS Document*/H2{font-size:56px;Font-weight:Bold;text-align:Center;}Body{width:Auto;Height:Auto;Background-image:URL (.. /images/03.png);background-repeat:no-repeat;background-size:100% 100%;background-attachment:fixed;background-position:Center;}#tDiv{Background-image:URL (.. /images/o1.png);background-repeat:Repeat;Margin-left:Auto;Margin-right:Auto;Margin-top:200px;width:550px;Height:Auto;font-size:10px;Border:2px solid #CCC;}#tDL{font-size:24px;text-align:Center;}

Login:

 PhpHeader("Content-type:text/html;charset=utf-8"); require_once"Sendemail/mysqlinfo/sqlinfo.php"; error_reporting(E_error|e_warning|E_parse);//disable display of false sirens, etc.     $sign=''; $_email=$_post[' _email ']; $_paswd=$_post[' _PASD '];//$_email= "2810718058@qq.com";//$_paswd= "1234567890";     $_activate= ' 1 ';//activating variables//connecting to a database     $con=@mysql_connect(DB_USER,DB_ROOT,DB_PWD) or die(' Connection error '); mysql_select_db(Db_name,$con) or die(' occured error '); mysql_query(' SET NAMES UTF8 ') or die(' Show error '); $sql= "SELECT * from chinesechess WHERE user_email= ' {$_email} ' and password= ' {$_paswd} ' and isactivated= ' {$_activate}'"; $result=mysql_query($sql,$con); $source=Mysql_fetch_array($result); if($source)    {        $sign= "Succeed"; $name=$source[' Nickname ']; $PASD=$source[' Password ']; $mail=$source[' User_email ']; Echo' Strings=name= '.$name.'
'; Echo' Pasd= '.$PASD.'
'; Echo' Mail= '.$mail.'
'; Echo' Sign= '.$sign.'
'; }Else { $sign= "Faild"; $name= "NULL"; $PASD= "000000"; $mail= "Null@cn.com"; Echo' Strings=name= '.$name.'
'; Echo' Pasd= '.$PASD.'
'; Echo' Mail= '.$mail.'
'; Echo' Sign= '.$sign.'
'; } Mysql_close();?>

Resource ID #num

Because I am a beginner, the MySQL query return value and other understanding is not enough, encountered a little confusion, mysql_query () only the Select,show,explain or DESCRIBE statement returns a resource identifier, if the query is executed incorrectly returns FALSE. To convert using the Mysql_fatch_array () function or the mysql_fetch_object () function, then manipulate the corresponding array or object.

In general, this part of the difficulties encountered is not many, after their own efforts are quickly resolved.

http://www.bkjia.com/PHPjc/1086209.html www.bkjia.com true http://www.bkjia.com/PHPjc/1086209.html techarticle Online Games Exercise Summary (1), the recent period of time in school also idle dry, anyway is a good long time, simply to do a "Chinese chess" online games to kill time to play. For a long time did not write ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.