2012-03-24 52 views
0

我有abc.php和def.php文件。例如,我想從abc.php中調用def.php。我找到了include()方法,但我不想def。 php在後臺激活。我希望瀏覽器根據def.php的html-php代碼重新繪製頁面。激活另一個php文件中的php文件

任何想法?

+0

要在運行背景 ? – safarov 2012-03-24 12:12:59

+0

[執行從另一個文件的PHP](http://stackoverflow.com/questions/1346708/executing-php-from-another-file) – Stefan 2012-03-24 12:15:02

+0

http://php.net/manual/en/function.http-redirect。 php參考這個 – 2012-03-24 12:24:01

回答

0

你可能在談論重定向。

你可以通過發出位置標題來實現。

請注意,這必須在任何內容發送到瀏覽器之前運行,因此它必須在頁面上顯示任何內容之前運行。如果您顯示一些文本並然後發送位置標題,它將不起作用,因爲標題必須始終在內容之前。

header('Location: def.php');

這會告訴瀏覽器重定向到def.php。

希望它有幫助!

+0

謝謝你的答案。但是,我有很多內容,我發送到瀏覽器在abc.php之前redirect = | – 2012-03-24 20:59:07

+0

爲此您將需要JavaScript。 在Google上瀏覽一下或者在StackExchange上提出另一個關於更多細節的問題,關於使用JavaScript在新窗口中打開一個新頁面。 – Teekin 2012-03-25 12:42:01

0

您可以返回的def.php

這裏的內容是一個例子:

頁:def.php

<?PHP 
    //do many things, but do not echo or print anything 
    $output ="<div> all the codes</div>"; // collect the markup like this 
    return $output; // return the output but still do not echo or print 
?> 

頁頁次:abc.php

//do its own processing 
$myDefPageOutput = include("def.php"); 
//This will only get the values of the return statement 

//Now user $myDefPageOutput wherever you want and redraw the page 
+0

謝謝Starx.But abc.php有很多內容(字符串,表單,鏈接)。我只想用def.php重新繪製頁面標記取決於abc.php中的條件。我猜這段代碼會添加內容def到abc內容的下面。我對不對? – 2012-03-24 20:56:57

+0

@SedatKURT,不是真的,它將def.php的內容添加到變量中,並且可以使用你喜歡的位置。回聲在頂部或底部,它的你的選擇 – Starx 2012-03-24 21:00:52

+0

嗯,但在同一時間有沒有在網頁上abc的內容? – 2012-03-24 21:26:18