Функция определения IP-адреса сайта
Простейший способ определения IP-адреса сайта на PHP:
<?php
$ip = gethostbyname('123.ru');
echo $ip;
?>
<?php
$ip = gethostbyname('123.ru');
echo $ip;
?>
<?php
$text="http://domain.ru";
$pic=ImageCreate(130,30);
$col1=ImageColorAllocate($pic,0,0,0);
$col2=ImageColorAllocate($pic,255,255,255);
ImageFilledRectangle($pic, 0, 0, 500, 30, $col2);
ImageString($pic, 3, 5, 8, $text, $col1);
Header("Content-type: image/jpeg");
ImageJPEG($pic);
ImageDestroy($pic);
?>
$file=file("/proc/stat");
$tmp=explode(" ",$file[0]);
$cpu1=$this->session->userdata("cpu1");
$cpu2=$this->session->userdata("cpu2");
$cpu3=$this->session->userdata("cpu3");
$cpu4=$this->session->userdata("cpu4");
$cpu=(100/($tmp[5]-$cpu4))/(($tmp[2]-$cpu1)+($tmp[3]-$cpu2)+($tmp[4]-$cpu3))*100;
$this->session->set_userdata(array("cpu1"=>$tmp[2],"cpu2"=>$tmp[3],"cpu3"=>$tmp[4],"cpu4"=>$tmp[5]));
> cat /proc/stat
cpu 2255 34 2290 22625563 6290 127 456 0 0
cpu0 1132 34 1441 11311718 3675 127 438 0 0
cpu1 1123 0 849 11313845 2614 0 18 0 0
intr 114930548 113199788 3 0 5 263 0 4 [... еще куча цифр ...]
...
> cat /proc/meminfo
MemTotal: 2052604 kB
MemFree: 246012 kB
Buffers: 792332 kB
Cached: 584716 kB
...
$file=file("/proc/meminfo");
$memory["total"]=substr($file[0],strpos($file[0]," "),strrpos($file[0]," ")-strpos($file[0]," "));
$memory["free"]=substr($file[1],strpos($file[1]," "),strrpos($file[1]," ")-strpos($file[1]," "));
> cat /proc/swaps
Filename Type Size Used Priority
/dev/sda1 partition 7811064 2732 -1
...
$file=file("/proc/swaps");
$tmp=explode("\t",substr($file[1],strpos($file[1],"partition")));
$swap["total"]=$tmp[1];
$swap["free"]=$tmp[1]-$tmp[2];
$drives=array();
if($dir=opendir("/mnt")){
while(false !== ($file = readdir($dir))) {
$arr=array();
if(($file!=".")&&($file!="..")){
$arr["path"]="/mnt/".$file;
$arr["free"]=disk_free_space("/mnt/".$file);
$arr["total"]=disk_total_space("/mnt/".$file);
$drives[]=$arr;
}
}
}
$uptime=exec("uptime");
$uptime=explode(",",substr($uptime,strpos($uptime,"up")+3));
$time=explode(":",$uptime[1]);
$uptime=$uptime[0]." ".$time[0]." hours ".$time[1]." minutes";
$result["cpu"]=$cpu;
$result["memory"]=$memory;
$result["swap"]=$swap;
$result["uptime"]=$uptime;
json_encode($result);
{"uptime":"34 days 5 hours 45 minutes","cpu":1.7361111111111,"memory":{"total":"2052604","free":"191424"},"swap":{"total":"7811064","free":7808332}}
var json=$.parseJSON(data);
$("#systemInfo").html("CPU: "+json.cpu+"<br />Memory free "+json.memory.free+" / "+json.memory.total);
Redirect 301 / http://www.you.com/new.htm
Redirect 301 /old/old.htm http://www.you.com/new.htm
RedirectPermanent / http://www.you.com/
RedirectPermanent /old-directory http://www.domain.com/new-directory/
Redirect permanent /test http://www.test.com/
Redirect permanent / http://enter.test.com/
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite\.com
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=permanent,L] .
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^rewrite\.htm$ rewrite.html [R=permanent]
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1.html [R=permanent]
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.ru/newdir/newpage.htm");
exit();
?>
<?
$ref=$_SERVER['QUERY_STRING'];
if ($ref!='') $ref='?'.$ref;
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://newdomain.com/'.$ref);
exit();
?>
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.new-url.com"
response.end
%>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">
<meta http-equiv='refresh' content='0; url=http://newdomain.com'>
setTimeout('document.forms["searchform"].Submit.click()', 100);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>SWFUpload</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>SWFUpload</h1>
<div id="uploadButton"></div>
<div id="status"></div>
<div id="images"></div>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/plugins/swfupload.queue.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
var swfu = new SWFUpload(
{
upload_url : "upload.php",
flash_url : "swfupload.swf",
button_placeholder_id : "uploadButton",
file_size_limit : "2 MB",
file_types : "*.jpg; *.png; *.jpeg; *.gif",
file_types_description : "Images",
file_upload_limit : "0",
debug: false,
button_image_url: "button.png",
button_width : 100,
button_height : 30,
button_text_left_padding: 15,
button_text_top_padding: 2,
button_text : "<span class=\"uploadBtn\">Обзор…</span>",
button_text_style : ".uploadBtn { font-size: 18px; font-family: Arial; background-color: #FF0000; }",
file_dialog_complete_handler : fileDialogComplete,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress
}
);
function uploadSuccess(file, serverData) {
$('#images').append($(serverData));
}
function uploadComplete(file) {
$('#status').append($('<p>Загрузка ' + file.name + ' завершена</p>'));
}
function uploadStart(file) {
$('#status').append($('<p>Начата загрузка файла ' + file.name + '</p>'));
return true;
}
function uploadProgress(file, bytesLoaded, bytesTotal) {
$('#status').append($('<p>Загружено ' + Math.round(bytesLoaded/bytesTotal*100) + '% файла ' + file.name + '</p>'));
}
function fileDialogComplete(numFilesSelected, numFilesQueued) {
$('#status').html($('<p>Выбрано ' + numFilesSelected + ' файл(ов), начинаем загрузку</p>'));
this.startUpload();
}
<?php
$uploadDir = 'uploads/'; //папка для хранения файлов
$allowedExt = array('jpg', 'jpeg', 'png', 'gif');
$maxFileSize = 2 * 1024 * 1024; //1 MB
//если получен файл
if (isset($_FILES)) {
//проверяем размер и тип файла
$ext = end(explode('.', strtolower($_FILES['Filedata']['name'])));
if (!in_array($ext, $allowedExt)) {
return;
}
if ($maxFileSize < $_FILES['Filedata']['size']) {
return;
}
if (is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$fileName = $uploadDir.$_FILES['Filedata']['name'];
//если файл с таким именем уже существует…
if (file_exists($fileName)) {
//…добавляем текущее время к имени файла
$nameParts = explode('.', $_FILES['Filedata']['name']);
$nameParts[count($nameParts)-2] .= time();
$fileName = $uploadDir.implode('.', $nameParts);
}
move_uploaded_file($_FILES['Filedata']['tmp_name'], $fileName);
echo '<img src="'.$fileName.'" alt="'.$fileName.'" />';
}
}
<html>
<head>
<title>Загрузка файлов на сервер</title>
</head>
<body>
<h2><p><b> Форма для загрузки файлов </b></p></h2>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="filename">
<input type="submit" value="Загрузить">
</form>
</body>
</html>
<html>
<head>
<title>Результат загрузки файла</title>
</head>
<body>
<?php
if($_FILES["filename"]["size"] > 1024*3*1024)
{
echo ("Размер файла превышает три мегабайта");
exit;
}
if(copy($_FILES["filename"]["tmp_name"],
"c:/temp/".$_FILES["filename"]["name"]))
{
echo("Файл успешно загружен
");
echo("Характеристики файла:
");
echo("Имя файла: ");
echo($_FILES["filename"]["name"]);
echo("
Размер файла: ");
echo($_FILES["filename"]["size"]);
echo("
Каталог для загрузки: ");
echo($_FILES["filename"]["tmp_name"]);
echo("
Тип файла: ");
echo($_FILES["filename"]["type"]);
} else {
echo("Ошибка загрузки файла");
}
?>
</body>
</html>
if($_FILES["filename"]["size"] > 1024*3*1024)
{
echo("Размер файла превышает три мегабайта");
exit;
}