程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php WEB上創建網站

php WEB上創建網站

編輯:關於PHP編程

我們用php來控制iis並且,在WEB上創建網站,管理刪除等功能哦。

<?
 我們用php來控制iis並且,在WEB上創建網站,管理刪除等功能哦。

# PHP控制站點程序
 #
 # 編寫人:韓湘子
 #
 # 郵箱:[email protected]
 #
 # MSN:[email protected]
 #
 # QQ:220670        
 #
 # 歡迎大家互相聯系討論
?> 
<link href="image/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
 background-color: #D4D0C8;
}
-->
</style>
<table width="980" border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
  <tr height=26>
    <td width="177" bgcolor="#E8E6E1">站點名稱</td>
    <td width="229" bgcolor="#E8E6E1">綁定域名</td>
    <td width="210" bgcolor="#E8E6E1">網站目錄</td>
    <td width="116" bgcolor="#E8E6E1">標識符</td>
    <td width="97" bgcolor="#E8E6E1">站點狀態</td>
    <td colspan="2" bgcolor="#E8E6E1"><div align="center">管理</div></td>
  </tr>
<?php

 $LocalHostObject = New Com ("IIS://localhost/w3svc") ;

 

 //刪除站點
 iF($Opt=="del"){
  $LocalHostObject->Delete("IIsWebServer",$ServerID);
  echo "<script>window.location='3.php';</script>";
 }

 //啟動和停止站點
 iF($Opt=="Status"){
  $Site2 = New Com ("IIS://LocalHost/w3svc/".$ServerID);
  $Site2->$Status;
 }


 //創建新站點
 iF($Submit){

  //創建目錄
//  mkdir(stripslashes($ServerDir));


  //添加用戶
  $usernameobj = New Com("WinNT://iim");
  $user = $usernameobj->Create("user",$ServerComm);


  //設置用戶名
  $user->SetInfo();

  //設置密碼
  $user->SetPassword($ServerComm);
 // $user->UserFlags('&H0040');
  $user->SetInfo();

  $usernameobj1 = New Com("WinNT://iim/".$ServerComm);
  $user->Description ="本用戶名由iiM在線管理系統創建.";
  $user->SetInfo();

  #就差一個把用戶加載到目錄上的權限問題了################################################################################################

 


  //創建站點


  $iissite = $LocalHostObject->Create("IIsWebServer",$ServerID);

  $aa = explode(",",$ServerBin);

//  //先設定站點的基本資料
  $iissite->ServerBindings = $aa;
  $iissite->ServerComment = $ServerComm;
  $iissite->AnonymousUserName = $ServerComm;
  $iissite->AnonymousUserPass = $ServerComm;
  $iissite->KeyType = "IIsWebServer";
  $iissite->EnableDefaultDoc = True;
  $iissite->DefaultDoc = "default.htm,default.asp,index.htm,index.html";
  $iissite->LogFileDirectory = "d:";
  $iissite->MaxBandwidth = '102400';
  $iissite->MaxConnections = '100';
  $iissite->LogType = "0";
  $iissite->AppIsolated = 0;
  $iissite->AuthBasic = False;
  $iissite->AuthNTLM = True;
  $iissite->HttpErrors = "404,*,FILE,C:WINDOWShelpiisHelpcommon404b.htm";
  //加上腳本映射
  foreach($scriptmapsubmit as $script){
   Switch($script){
    Case "asp";
     $sc[] = ".asa,C:WINDOWSsystem32inetsrvasp.dll,5";
     $sc[] = ".asp,C:WINDOWSsystem32inetsrvasp.dll,5";
     break;
    Case "php";
     $sc[] = ".php,E:softphp-5.2.3-Win32(1)php5isapi.dll,5";
     $sc[] = ".php3,E:softphp-5.2.3-Win32(1)php5isapi.dll,5";
     $sc[] = ".php4,E:softphp-5.2.3-Win32(1)php5isapi.dll,5";
     $sc[] = ".php5,E:softphp-5.2.3-Win32(1)php5isapi.dll,5";
     $sc[] = ".php6,E:softphp-5.2.3-Win32(1)php5isapi.dll,5";
     break;
    Case "cgi";
     echo "cgi<br>";
     break;
    Case "aspnet";
     echo "asp.net<br>";
     break;
    Case "html";
     echo "html";
     break;

   }
   
  }
  $iissite->ScriptMaps = $sc;
  $iissite->SetInfo();

  //再設定站點目錄
  $iisdir = $iissite->Create("IIsWebVirtualDir","ROOT");
  $ServerDir1 = stripslashes($ServerDir);
  $iisdir->Path = $ServerDir1;
  $iisdir->AppCreate(True) ;
  $iisdir->AccessRead = True;
  $iisdir->EnableDirBrowsing = False;

  //允許父路徑,也就是允許.
  $iisdir->AspEnableParentPaths = True;
  $iisdir->AccessScript = True;
  $iisdir->AppFriendlyName = "默認應用程序";
  $iisdir->SetInfo();
 
  //啟動站點
  $Site1->Start;

  echo "<script>window.location='3.php';</script>";

 }

 //列出所有網站
 ForEach($LocalHostObject as $WebSiteName){
  iF($WebSiteName->Class == "IIsWebServer"){
   $Site = New Com ("IIS://localhost/w3svc/".$WebSiteName->Name) ;
   //站點狀態
   $SiteStatus1 = $Site->Status ;
   Switch($SiteStatus1){
    Case "2" ;
     $SiteStatus = "<a href=?Opt=Status&Status=stop&ServerID=$Site->Name>正常</a>" ;
     break;
    Case "6" ;
     $SiteStatus = "<a href=?Opt=Status&Status=start&ServerID=$Site->Name><font color=red>暫停</font></a>" ;
     break;
    Case "4" ;
     $SiteStatus = "<a href=?Opt=Status&Status=start&ServerID=$Site->Name><font color=red>停止</font></a>" ;
     break;
   }


?>
  <tr height=26>
    <td bgcolor="#F4F3F2" ><?php Echo $Site->ServerComment ; ?></td>
    <td bgcolor="#F4F3F2">
<?php
 //得出綁定的域名
   $BinDings = $Site->ServerBinDings;
   ForEach($BinDings as $BinDing){
    List($ip, $Port, $Domain) = Explode(":",$BinDing);
    Echo $Domain ."<br>";
   }

?> </td>
    <td bgcolor="#F4F3F2">
<?
 //網站目錄

 $getRootDir = $Site->GetObject("IIsWebVirtualDir","ROOT");
 echo $getRootDir->Path;
?></td>
    <td bgcolor="#F4F3F2"><?php Echo $Site->Name ; ?></td>
    <td bgcolor="#F4F3F2"><?php Echo $SiteStatus ; ?></td>
    <td width="40" bgcolor="#F4F3F2"><div align="center"><a href=?Opt=del&ServerID=<?php Echo $Site->Name?>>刪除</a></div></td>
    <td width="33" bgcolor="#F4F3F2"><div align="center"><a href=33.php?ServerID=<?php Echo $Site->Name ; ?>>管理</a></div></td>
  </tr>
<?php
  }
 }
 unset($LocalHostObject);
 unset($Site);
 unset($Site1);
 unset($Site2);
?>
</table>
 <form id="form1" name="form1" method="post" action="">
   <table width="100%" border="0" cellspacing="0" cellpadding="3">
     <tr>
       <td width="8%">站點名稱</td>
       <td width="92%"><input type="text" name="ServerComm" /></td>
     </tr>
     <tr>
       <td>站點目錄 </td>
       <td><input type="text" name="ServerDir" value="F:user"/></td>
     </tr>
     <tr>
       <td>站點ID號 </td>
       <td><input type="text" name="ServerID"/></td>
     </tr>
     <tr>
       <td>Serverbin</td>
       <td><textarea name="ServerBin" cols="80" rows="5"></textarea></td>
     </tr>
     <tr>
       <td>腳本映射</td>
       <td><input name="scriptmapsubmit[]" type="checkbox" id="scriptmapsubmit" value="asp" />
ASP
  <input name="scriptmapsubmit[]" type="checkbox" id="scriptmapsubmit" value="php" />
PHP
<input name="scriptmapsubmit[]" type="checkbox" id="scriptmapsubmit" value="cgi" />
CGI
<input name="scriptmapsubmit[]" type="checkbox" id="scriptmapsubmit" value="aspnet" />
ASP.NET
<input name="scriptmapsubmit[]" type="checkbox" id="scriptmapsubmit" value="html" checked="checked" />
HTML</td>
     </tr>
     <tr>
       <td><input type="submit" name="Submit" value="Submit" /></td>
       <td>&nbsp;</td>
     </tr>
   </table>
</form>
 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved