2014-11-02 173 views
0

我正在C中創建一個簡單的網絡服務器並嘗試執行PHP腳本。我可以通過調用: execl(「/ usr/bin/php」,「/ usr/bin/php」,「-q」,phpFile,(char *)NULL)來執行此操作。在C執行PHP腳本

但是,我無法發送獲取參數到這個文件。例如:./index.php?name=test 我該怎麼做?

回答

0

難道你只是在PHP文件的末尾追加參數? 我認爲應該這樣的工作:

char phpFile [128] = "./index.php"; 
    char * args = "name=test"; 
    char * args2 = "city=paris"; 
    strcat(phpFile, "?"); 
    strcat(phpFile, args); 
    strcat(phpFile, "&"); 
    strcat(phpFile, args2); // etc. if you want to add more args. 
+0

我可以做到這一點。但execl不會給出適當的結果 – exterminator 2014-11-02 13:13:31