PHP Apache Virtual Host Manager for XAMPP Windows
How?
Blog Archive
▼
14
(1)
▼
Nov
(1)
PHP Apache Virtual Host Manager for XAMPP Windows
►
12
(8)
►
Jun
(5)
►
Apr
(1)
►
Mar
(1)
►
Feb
(1)
►
11
(59)
►
Oct
(1)
►
Sep
(1)
►
Aug
(3)
►
Jul
(23)
►
Jun
(6)
►
May
(17)
►
Apr
(5)
►
Mar
(1)
►
Jan
(2)
►
10
(3)
►
May
(3)
Followers
Listed
Google PageRank Checker PRBbutton
auto FWS
mBed Bugs
Programing
VB.net
CSharp
Aero Glass
C/C++
Pascal/TPW
Software
Win7Aero Programing
Tas Wanita Murah
Visitor
Large View
Feedjit Live Blog Stats
S
H
A
R
E
Saturday, November 08, 2014
PHP Apache Virtual Host Manager for XAMPP Windows
Use this code for adding virtual on your xampp windows sistem.
<?php $vhost_file = "../apache/conf/extra/httpd-vhosts.conf"; $host_file = "c:\\windows\\system32\\/drivers\\etc\\hosts"; $template=<<<end <virtualhost {HOST}:80> ServerAdmin admin@{HOST} DocumentRoot "{HOST-DIR}" ServerName {HOST} ServerAlias www.{HOST} ErrorLog "logs/{HOST}-error.log" CustomLog "logs/{HOST}-access.log" common </VirtualHost> end; $host_konten = true; if($_POST){ $new = str_replace('{HOST}', $_POST['host'], $template); $new = str_replace('{HOST-DIR}', $_POST['host-dir'], $new); if(file_put_contents($vhost_file, "\r\n".$new,FILE_APPEND)){ $msg = 'OK'; } $sn = $_POST['host']; $host_add = "\r\n127.0.0.1\t$sn\r\n127.0.0.1\twww.$sn\r\n"; $host_konten = file_put_contents($host_file, "\r\n".$host_add,FILE_APPEND); } $konten = file_get_contents($vhost_file); if(!$konten){ echo "Error: Can't read vhost_file: $vhost_file."; return; } //echo $konten; ?> <!DOCTYPE html> <html> <head> <title>PHP Apache Virtual Host Manager for XAMPP Windows</title> </head> <body style="background: rgb(249, 249, 249);color: rgb(153, 0, 186);font-family: verdana;font-size: medium;margin: 39px;"> <header> <h1> PHP Apache Virtual Host Manager for XAMPP Windows</h1> <p> please make backup to your vhost.conf file before applying changes.</p> </header> <article> <form method="post"> <?php if($msg = 'OK'){ if(!$host_konten){ echo "<div style='color:red'> Can't modify hosts windows file</div> "; } echo "<h2 style='color:green'> vHost Added!.</h2> <p> Now restart your apache</p> <hr> "; } //$pattern = '/^<VirtualHost\s[\*|a-zA-Z0-9]+\:[0-9]+>(.*)/i'; $pattern_open = '/^<virtualhost\s(.*)>/i'; $pattern_close = '/^<\/virtualhost>/i'; $lines = explode("\r\n", $konten); $hosts = array(); $pos = 0; $is_open = false; foreach ($lines as $key => $value) { $value = trim($value); if($is_open){ if(preg_match($pattern_close, $value)){ //$hosts[$pos]['close_tag'] = $value; $is_open = false; $pos++; }else{ $v = explode(" ", $value); $hosts[$pos][$v[0]] = $v[1]; } }elseif(preg_match($pattern_open, $value)){ $is_open = true; $hosts[$pos] = array();//'open_tag' => $value); } } foreach ($hosts as $h) { echo "<h3> $h[ServerName]</h3> "; echo '<div> '; foreach ($h as $k => $v) { echo "$k : $v<br/>"; } echo '</div> '; } ?> <hr> <h2> Add New</h2> ServerName: <input type="text" name="host" value=""><br/> DocumentRoot: <input type="text" name="host-dir" value="c:\xampp\htdocs\"> <br/> <input type="submit" value="SAVE AND WRITE!"> </form> </article> <hr/> <footer> © 2014 Klampok Child — <a href='http://developer-id.com/'>Developer-id.com</a> </footer> </body> </html>
0 comments:
Post a Comment
Older Post
Home
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment