<abbr id="a1ome"></abbr>
    <tfoot id="a1ome"></tfoot>

    1.  本聊天室需使用頁框,您的瀏覽器無法使用 <\/body> <\/noframes> <\/frameset> <\/html><\/pre>

      程式中以 frame 帶出二支 PHP 程式,建議將它們放在同一目錄之中,例如 \/chatroom,以便日后維護(hù)。另外,為了 list.php 及 post.php 可以使用相同的變數(shù),下例將共通的變路路徑放在 env.inc 中,可以將它放在 \/chatroom 或是 Web 伺服器 (如 Apache) 的 PHP include 設(shè)定路徑中。<\/p>

      <\/pre>

      聊天室的后端可以設(shè)計(jì)的很簡單,單純的使用檔案來做,也可以弄個(gè)資料庫,將聊天的內(nèi)容丟入,若是真的很在意系統(tǒng)效率,或許可以考慮使用 UNIX 的行程通訊 IPC 了。<\/p>

      本節(jié)即將使用者留言的內(nèi)容放入檔案中,在這兒的例子大部份都使用 UNIX\/Linux 的外部指令。若系統(tǒng)無該指令 (或稱程式),請自行安裝相關(guān)程式。<\/p>

      實(shí)際上將資料丟入檔案中會(huì)比使用資料庫還快,若還很在乎速度,可以在 UNIX 機(jī)器中裝上 RAM Disk,再將檔案的存取路徑都設(shè)在該 RAM Disk 上,保證存取速度能滿足嚴(yán)苛的要求。在有些以高速度搜尋引擎為號(hào)召的網(wǎng)站,甚至將整個(gè)資料庫資料都放到 RAM Disk 中,馬上讓系統(tǒng)速度提高十倍百倍,而且 RAM 的價(jià)格和其它解決方案相比的話還算很便宜。若使用 Windows NT,那就沒辦法了,看微軟什么時(shí)候提供,或者用 Third Party 的產(chǎn)品了。<\/p>

      有些使用者可能對 UNIX 還不是很熟,在這兒先簡介會(huì)用到的指令:<\/p>

      touch: 建立新檔案,或修改舊檔的最后更新日期。<\/p>

      echo 加上二個(gè)大于符號(hào): 將字串顯示轉(zhuǎn)向到指定的地方。<\/p>

      tail: 顯示檔案最后數(shù)行的資料,內(nèi)定值為十行,可使用減號(hào)加數(shù)字,修改欲顯示的行數(shù)。<\/p>

      下面為送出及處理留言字串的程式,程式用到 env.inc 的檔案。<\/p>

      \".date(\"h:i:s\").\"<\/font>-\".$chatuser.\"<\/font>: \".$chattext; \r\n  $cmdstr=\"echo \"\".$chatstr.\"\" >> \".$chatfile; \r\n  if (!file_exists($chatfile)) passthru(\"touch \".$chatfile); \r\n  passthru($cmdstr); \r\n} \r\n><\/pre>
       \r\n
      

      亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

       \r\n method=post> \r\n \r\n匿稱:<\/td> \r\n\"><\/td> \r\n發(fā)言:<\/td> \r\n<\/td> \r\n<\/td> \r\n<\/tr><\/table> \r\n<\/form> \r\n<\/body> \r\n<\/html><\/pre>

      程式先檢查是否有輸入字串,若無匿名及發(fā)言內(nèi)容字串則顯示發(fā)言的表單 (Form),若有資料則將字串及當(dāng)時(shí)時(shí)間存入檔案中 (利用 UNIX 的轉(zhuǎn)向指令)。當(dāng)然,為了防止錯(cuò)誤,先檢查是否有檔案可存檔,若沒有則先 touch 該檔,例中的檔案就是 \/tmp\/abc。<\/p>

       \">   < \/\/ 檔名: list.php require(\"env.inc\");\r\nif (!file_exists($chatfile)) {  echo \"尚未開張<\/body><\/html>\";   exit; }\r\n$uniqfile=$tempdir.uniqid(rand()); $shellcmd=\"\/usr\/bin\/tail -50 \".$chatfile. \" > \".$uniqfile; passthru($shellcmd); $chatfilearray=file($uniqfile); $j=count($chatfilearray); for ($i=1; $i<=$j; $i++) {  echo $chatfilearray[$j-$i].\"
       \"; } unlink($uniqfile); > <\/body> <\/html><\/pre>

      上面的程式就是使用 Client Pull 的技術(shù),每五秒就重新更新一次。同樣地,它也 require 共用的 env.inc 檔,要改變其中的變數(shù)時(shí),馬上就可以讓所有的程式用到,這對開發(fā)網(wǎng)站來說,是蠻重要的方法,可以將網(wǎng)頁程式中都會(huì)出現(xiàn)的地方。例如 Copyright (C) 1996-2000 的字串,放在一個(gè)檔案上,到了新的一年,只要改一個(gè)檔,整個(gè)站都改了。<\/p>

      if (!file_exists($chatfile)) {  echo \"尚未開張<\/body><\/html>\";   exit; }\r\n$uniqfile=$tempdir.uniqid(rand()); $shellcmd=\"\/usr\/bin\/tail -50 \".$chatfile. \" > \".$uniqfile; passthru($shellcmd);<\/pre>

      程式先檢查有沒有使用者發(fā)送聊天內(nèi)容的檔案 \/tmp\/abc,若沒有就顯示尚未開張,等使用者送聊天內(nèi)容。若已有聊天資料,就抓出最后五十筆,在在另外的檔案中準(zhǔn)備顯示。<\/p>

      $chatfilearray=file($uniqfile); \r\n$j=count($chatfilearray); \r\nfor ($i=1; $i<=$j; $i++) {\r\n  echo $chatfilearray[$j-$i].\"
       \"; \r\n} \r\nunlink($uniqfile);<\/pre>

      將檔案讀入陣列變數(shù) $chatfilearray 中,并以最后的資料最先顯示的方式送給瀏覽器端,當(dāng)然可以使用對陣列排序的方法,但確定一定時(shí)最后存入的資料在最后面,將它排序?qū)嵲诤芾速M(fèi) CPU 時(shí)間,因此就從最后 echo 到最前面的資料。使用完成還要用 unlink() 指令,將臨時(shí)檔殺掉。?<\/p>"}

      Home php教程 php手冊 一個(gè)PHP入門源程序代碼

      一個(gè)PHP入門源程序代碼

      Apr 18, 2017 pm 03:31 PM

      一個(gè)簡單的PHP入門源程序,需要的朋友們可以看一下。

      引用“星空浪子”php中文文檔的例子:

      聊天室,是 Web 站上打發(fā)無聊人士的秘密武器。同時(shí),站長或其它人員也可以在這兒殺時(shí)間。甚至發(fā)生一段轟轟烈烈的網(wǎng)路戀情呢,就算沒有,起碼可以增加打字的速度。?
      聊天室,其實(shí)就是多人共同使用的 CGI 程式。程式將每個(gè)人輸入的字串,依系統(tǒng)接收完成的時(shí)間整理過后,再送給各個(gè)使用者。而 Web 聊天室和 BBS 的聊天室不同的地方是 BBS 聊天室可以每收到一句話,就馬上分送給每位在聊天室的網(wǎng)路使用者;Web 由于 CGI 程式不能像 BBS 的 telnet 一直連線,Web CGI 必須以最快的速度將資訊送出,然后結(jié)束連線。會(huì)形成這種情形,就是因?yàn)?Web 聊天室還是使用 HTTP 傳輸協(xié)定,在 HTTP 實(shí)作的版本,無論是 0.9、1.0 或是 1.1 版都不能長期占據(jù)網(wǎng)路連線的 Port。

      為了解決資料無法馬上傳輸?shù)膯栴},及更新訊息的問題,Netscape 在 3.0 版瀏覽器之后使用了新的技術(shù),而 Internet Explorer 也實(shí)作了這些 Netscape 研發(fā)出來的技術(shù)。Netscape 將它分成 Server Push 及 Client Pull 二種技術(shù)。Server Push 由 Web 伺服器將資料以多重 MIME 編碼,送給使用者端,目前較少網(wǎng)站使用這種方式;而 Client Pull 則利用了 HTML 的 meta 標(biāo)簽,并利用 http-equiv="Refresh" 的屬性,表示資料要重新載入,至于載入時(shí)間,則利用 content 屬性來達(dá)成。

      標(biāo)簽通常都放在 .. 的區(qū)段中,以便讓瀏覽器可以僅早準(zhǔn)備更新使用者端的網(wǎng)頁。下面為 meta 和 PHP 合用的例子,設(shè)定為每十五秒重新載入一次。

      如果不用 Server Push 或是 Client Pull 來做聊天室,是否有其它的方法,讓 Web 的瀏覽器能聊天呢?答案是肯定的??梢允褂?Java 或是 ActiveX (限 IE4、5) 來做甚至自行開發(fā)專屬的 Browser Plug-in 程式 (如奇摩的聊天室),不過這就和 PHP 沒有關(guān)系了,不是我們要的重點(diǎn)。

      除此之外,由于定期更新所有網(wǎng)友的留言,為了怕寫了一半因?yàn)?refresh 而被清掉尚未寫好的字串,因此將聊天室以 frame 的頁框技術(shù)來做是有必要的。下例就是聊天室的主程式。

      <html> <head> <title>聊天室</title> </head> <frameset rows="*,40" border=1> <frame src="list.php" name=list scrolling=auto> <frame src="post.php" name=post scrolling=no> <noframes> <body> 本聊天室需使用頁框,您的瀏覽器無法使用 </body> </noframes> </frameset> </html>


      程式中以 frame 帶出二支 PHP 程式,建議將它們放在同一目錄之中,例如 /chatroom,以便日后維護(hù)。另外,為了 list.php 及 post.php 可以使用相同的變數(shù),下例將共通的變路路徑放在 env.inc 中,可以將它放在 /chatroom 或是 Web 伺服器 (如 Apache) 的 PHP include 設(shè)定路徑中。

      <php // 檔名: env.inc $tempdir="/tmp/"; $chatfile="/tmp/abc"; >

      聊天室的后端可以設(shè)計(jì)的很簡單,單純的使用檔案來做,也可以弄個(gè)資料庫,將聊天的內(nèi)容丟入,若是真的很在意系統(tǒng)效率,或許可以考慮使用 UNIX 的行程通訊 IPC 了。

      本節(jié)即將使用者留言的內(nèi)容放入檔案中,在這兒的例子大部份都使用 UNIX/Linux 的外部指令。若系統(tǒng)無該指令 (或稱程式),請自行安裝相關(guān)程式。

      實(shí)際上將資料丟入檔案中會(huì)比使用資料庫還快,若還很在乎速度,可以在 UNIX 機(jī)器中裝上 RAM Disk,再將檔案的存取路徑都設(shè)在該 RAM Disk 上,保證存取速度能滿足嚴(yán)苛的要求。在有些以高速度搜尋引擎為號(hào)召的網(wǎng)站,甚至將整個(gè)資料庫資料都放到 RAM Disk 中,馬上讓系統(tǒng)速度提高十倍百倍,而且 RAM 的價(jià)格和其它解決方案相比的話還算很便宜。若使用 Windows NT,那就沒辦法了,看微軟什么時(shí)候提供,或者用 Third Party 的產(chǎn)品了。

      有些使用者可能對 UNIX 還不是很熟,在這兒先簡介會(huì)用到的指令:

      touch: 建立新檔案,或修改舊檔的最后更新日期。

      echo 加上二個(gè)大于符號(hào): 將字串顯示轉(zhuǎn)向到指定的地方。

      tail: 顯示檔案最后數(shù)行的資料,內(nèi)定值為十行,可使用減號(hào)加數(shù)字,修改欲顯示的行數(shù)。

      下面為送出及處理留言字串的程式,程式用到 env.inc 的檔案。

      <php 
      // 檔名: post.php 
      require("env.inc"); 
      if (($chatuser!="") and ($chattext!="")) {
        $chatstr="<font color=8080ff>".date("h:i:s")."</font>-<font color=ff8080>".$chatuser."</font>: ".$chattext; 
        $cmdstr="echo "".$chatstr."" >> ".$chatfile; 
        if (!file_exists($chatfile)) passthru("touch ".$chatfile); 
        passthru($cmdstr); 
      } 
      >
      <html> 
      <body bgcolor=ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0> 
      <form action=< echo $PHP_SELF; > method=post> 
      <table border=0 width=100%><tr> 
      <td align=right>匿稱:</td> 
      <td><input type=text name=chatuser size=8 value="< echo $chatuser; >"></td> 
      <td align=right>發(fā)言:</td> 
      <td><input type=text name=chattext size=30 maxlength=500></td> 
      <td><div align=right><input type=submit value="送出"></td> 
      </tr></table> 
      </form> 
      </body> 
      </html>


      程式先檢查是否有輸入字串,若無匿名及發(fā)言內(nèi)容字串則顯示發(fā)言的表單 (Form),若有資料則將字串及當(dāng)時(shí)時(shí)間存入檔案中 (利用 UNIX 的轉(zhuǎn)向指令)。當(dāng)然,為了防止錯(cuò)誤,先檢查是否有檔案可存檔,若沒有則先 touch 該檔,例中的檔案就是 /tmp/abc。

      <html> <meta http-equiv="Refresh" content="5; url=< echo $PHP_SELF; >"> <meta content="text/html; charset=gb2312" http-equiv=Content-Type> <body bgcolor=ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0> < // 檔名: list.php require("env.inc");
      if (!file_exists($chatfile)) {  echo "尚未開張</body></html>";   exit; }
      $uniqfile=$tempdir.uniqid(rand()); $shellcmd="/usr/bin/tail -50 ".$chatfile. " > ".$uniqfile; passthru($shellcmd); $chatfilearray=file($uniqfile); $j=count($chatfilearray); for ($i=1; $i<=$j; $i++) {  echo $chatfilearray[$j-$i]."<br> "; } unlink($uniqfile); > </body> </html>

      上面的程式就是使用 Client Pull 的技術(shù),每五秒就重新更新一次。同樣地,它也 require 共用的 env.inc 檔,要改變其中的變數(shù)時(shí),馬上就可以讓所有的程式用到,這對開發(fā)網(wǎng)站來說,是蠻重要的方法,可以將網(wǎng)頁程式中都會(huì)出現(xiàn)的地方。例如 Copyright (C) 1996-2000 的字串,放在一個(gè)檔案上,到了新的一年,只要改一個(gè)檔,整個(gè)站都改了。

      if (!file_exists($chatfile)) {  echo "尚未開張</body></html>";   exit; }
      $uniqfile=$tempdir.uniqid(rand()); $shellcmd="/usr/bin/tail -50 ".$chatfile. " > ".$uniqfile; passthru($shellcmd);

      程式先檢查有沒有使用者發(fā)送聊天內(nèi)容的檔案 /tmp/abc,若沒有就顯示尚未開張,等使用者送聊天內(nèi)容。若已有聊天資料,就抓出最后五十筆,在在另外的檔案中準(zhǔn)備顯示。

      $chatfilearray=file($uniqfile); 
      $j=count($chatfilearray); 
      for ($i=1; $i<=$j; $i++) {
        echo $chatfilearray[$j-$i]."<br> "; 
      } 
      unlink($uniqfile);

      將檔案讀入陣列變數(shù) $chatfilearray 中,并以最后的資料最先顯示的方式送給瀏覽器端,當(dāng)然可以使用對陣列排序的方法,但確定一定時(shí)最后存入的資料在最后面,將它排序?qū)嵲诤芾速M(fèi) CPU 時(shí)間,因此就從最后 echo 到最前面的資料。使用完成還要用 unlink() 指令,將臨時(shí)檔殺掉。?

      Statement of this Website
      The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

      Hot AI Tools

      Undress AI Tool

      Undress AI Tool

      Undress images for free

      Undresser.AI Undress

      Undresser.AI Undress

      AI-powered app for creating realistic nude photos

      AI Clothes Remover

      AI Clothes Remover

      Online AI tool for removing clothes from photos.

      Clothoff.io

      Clothoff.io

      AI clothes remover

      Video Face Swap

      Video Face Swap

      Swap faces in any video effortlessly with our completely free AI face swap tool!

      Hot Tools

      Notepad++7.3.1

      Notepad++7.3.1

      Easy-to-use and free code editor

      SublimeText3 Chinese version

      SublimeText3 Chinese version

      Chinese version, very easy to use

      Zend Studio 13.0.1

      Zend Studio 13.0.1

      Powerful PHP integrated development environment

      Dreamweaver CS6

      Dreamweaver CS6

      Visual web development tools

      SublimeText3 Mac version

      SublimeText3 Mac version

      God-level code editing software (SublimeText3)

      How to use PHP to build social sharing functions PHP sharing interface integration practice How to use PHP to build social sharing functions PHP sharing interface integration practice Jul 25, 2025 pm 08:51 PM

      The core method of building social sharing functions in PHP is to dynamically generate sharing links that meet the requirements of each platform. 1. First get the current page or specified URL and article information; 2. Use urlencode to encode the parameters; 3. Splice and generate sharing links according to the protocols of each platform; 4. Display links on the front end for users to click and share; 5. Dynamically generate OG tags on the page to optimize sharing content display; 6. Be sure to escape user input to prevent XSS attacks. This method does not require complex authentication, has low maintenance costs, and is suitable for most content sharing needs.

      How to use PHP combined with AI to achieve text error correction PHP syntax detection and optimization How to use PHP combined with AI to achieve text error correction PHP syntax detection and optimization Jul 25, 2025 pm 08:57 PM

      To realize text error correction and syntax optimization with AI, you need to follow the following steps: 1. Select a suitable AI model or API, such as Baidu, Tencent API or open source NLP library; 2. Call the API through PHP's curl or Guzzle and process the return results; 3. Display error correction information in the application and allow users to choose whether to adopt it; 4. Use php-l and PHP_CodeSniffer for syntax detection and code optimization; 5. Continuously collect feedback and update the model or rules to improve the effect. When choosing AIAPI, focus on evaluating accuracy, response speed, price and support for PHP. Code optimization should follow PSR specifications, use cache reasonably, avoid circular queries, review code regularly, and use X

      PHP creates a blog comment system to monetize PHP comment review and anti-brush strategy PHP creates a blog comment system to monetize PHP comment review and anti-brush strategy Jul 25, 2025 pm 08:27 PM

      1. Maximizing the commercial value of the comment system requires combining native advertising precise delivery, user paid value-added services (such as uploading pictures, top-up comments), influence incentive mechanism based on comment quality, and compliance anonymous data insight monetization; 2. The audit strategy should adopt a combination of pre-audit dynamic keyword filtering and user reporting mechanisms, supplemented by comment quality rating to achieve content hierarchical exposure; 3. Anti-brushing requires the construction of multi-layer defense: reCAPTCHAv3 sensorless verification, Honeypot honeypot field recognition robot, IP and timestamp frequency limit prevents watering, and content pattern recognition marks suspicious comments, and continuously iterate to deal with attacks.

      PHP calls AI intelligent voice assistant PHP voice interaction system construction PHP calls AI intelligent voice assistant PHP voice interaction system construction Jul 25, 2025 pm 08:45 PM

      User voice input is captured and sent to the PHP backend through the MediaRecorder API of the front-end JavaScript; 2. PHP saves the audio as a temporary file and calls STTAPI (such as Google or Baidu voice recognition) to convert it into text; 3. PHP sends the text to an AI service (such as OpenAIGPT) to obtain intelligent reply; 4. PHP then calls TTSAPI (such as Baidu or Google voice synthesis) to convert the reply to a voice file; 5. PHP streams the voice file back to the front-end to play, completing interaction. The entire process is dominated by PHP to ensure seamless connection between all links.

      How to use PHP to combine AI to generate image. PHP automatically generates art works How to use PHP to combine AI to generate image. PHP automatically generates art works Jul 25, 2025 pm 07:21 PM

      PHP does not directly perform AI image processing, but integrates through APIs, because it is good at web development rather than computing-intensive tasks. API integration can achieve professional division of labor, reduce costs, and improve efficiency; 2. Integrating key technologies include using Guzzle or cURL to send HTTP requests, JSON data encoding and decoding, API key security authentication, asynchronous queue processing time-consuming tasks, robust error handling and retry mechanism, image storage and display; 3. Common challenges include API cost out of control, uncontrollable generation results, poor user experience, security risks and difficult data management. The response strategies are setting user quotas and caches, providing propt guidance and multi-picture selection, asynchronous notifications and progress prompts, key environment variable storage and content audit, and cloud storage.

      PHP realizes commodity inventory management and monetization PHP inventory synchronization and alarm mechanism PHP realizes commodity inventory management and monetization PHP inventory synchronization and alarm mechanism Jul 25, 2025 pm 08:30 PM

      PHP ensures inventory deduction atomicity through database transactions and FORUPDATE row locks to prevent high concurrent overselling; 2. Multi-platform inventory consistency depends on centralized management and event-driven synchronization, combining API/Webhook notifications and message queues to ensure reliable data transmission; 3. The alarm mechanism should set low inventory, zero/negative inventory, unsalable sales, replenishment cycles and abnormal fluctuations strategies in different scenarios, and select DingTalk, SMS or Email Responsible Persons according to the urgency, and the alarm information must be complete and clear to achieve business adaptation and rapid response.

      Beyond the LAMP Stack: PHP's Role in Modern Enterprise Architecture Beyond the LAMP Stack: PHP's Role in Modern Enterprise Architecture Jul 27, 2025 am 04:31 AM

      PHPisstillrelevantinmodernenterpriseenvironments.1.ModernPHP(7.xand8.x)offersperformancegains,stricttyping,JITcompilation,andmodernsyntax,makingitsuitableforlarge-scaleapplications.2.PHPintegrateseffectivelyinhybridarchitectures,servingasanAPIgateway

      PHP integrated AI speech recognition and translator PHP meeting record automatic generation solution PHP integrated AI speech recognition and translator PHP meeting record automatic generation solution Jul 25, 2025 pm 07:06 PM

      Select the appropriate AI voice recognition service and integrate PHPSDK; 2. Use PHP to call ffmpeg to convert recordings into API-required formats (such as wav); 3. Upload files to cloud storage and call API asynchronous recognition; 4. Analyze JSON results and organize text using NLP technology; 5. Generate Word or Markdown documents to complete the automation of meeting records. The entire process needs to ensure data encryption, access control and compliance to ensure privacy and security.

      See all articles