当前位置:编程学习 > php >>

php WEB上创建网站

<?
 我们用php来控制iis并且,在WEB上创建网站,管理删除等功能哦。

# PHP控制站点程序
 #
 # 编写人:韩湘子
 #
 # 邮箱:hanxiangzi@gmail.com
 #
 # MSN:hanxiangzi@gmail.com
 #
 # 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> </td>
     </tr>
   </table>
</form>
 

补充:Php教程,Php高级应用
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,