Re: [請益] php 內執行 php

看板PHP作者 (銀色)時間15年前 (2010/03/11 21:57), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《addbear (無家的小孩)》之銘言: : 請問如何讓一個 php 的程式碼去執行另一個 php 檔案, : 之前的學長是用 <?php system("./counter.php"); ?> 來啟動計數器, : 可是現在我試著更新 php 版本,導致沒有 php 的 command 指令, : 我應該如何修改 php 程式,讓它能自動啟動其它的 php 呢? : 我也試著用 <?php include_once("./counter.php"); ?> 來修改, : 可是會有 Cannot modify header information - header already sent 之訊息, : 有無其它的方法呢? 用 system call 是在背後呼叫,include 進來等於是當場呼叫, 如果要用 include,第一是要先小心有沒有前面變數干擾的問題。 從錯誤訊息 Cannot modify header information - header already sent 看起來應該是這隻 php 會搶在你其他 header 前丟出資訊, 如果要用 include,不妨藉由 ob 來把輸出吃掉, http://php.net/manual/en/function.ob-start.php http://www.php.net/manual/en/function.ob-get-contents.php ob_start (); include_once ("./counter.php"); $result = ob_get_contents (); 記得還是要找個地方把 $result 吐出來檢查一下… :P -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.136.225.119

03/12 09:57, , 1F
感謝,犯人是計數器會送出 header 資訊且將它指定為 image
03/12 09:57, 1F

03/12 18:47, , 2F
img src=
03/12 18:47, 2F
文章代碼(AID): #1BcFRAMD (PHP)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1BcFRAMD (PHP)