Как к PHP прикрутить JavaScript и CSS скрипты

Ответить
Felixx
Сообщения: 4
Зарегистрирован: 24.11.2010
Дан скрипт на PHP

Код: Выделить всё

<? 

error_reporting(0);

include "config.php";

function replacer ($text) { 
$text=str_replace("&#032;",' ',$text);
$text=str_replace(">",'>',$text);
$text=str_replace("<",'<',$text);
$text=str_replace("\"",'"',$text);
$text=preg_replace("/\n\n/",'<p>',$text);
$text=preg_replace("/\n/",'<br>',$text);
$text=preg_replace("/\\\$/",'&#036;',$text);
$text=preg_replace("/\r/",'',$text);
$text=preg_replace("/\\\/",'&#092;',$text);
$text=str_replace("\r\n","<br> ",$text);
$text=str_replace("\n\n",'<p>',$text);
$text=str_replace("\n",'<br> ',$text);
$text=str_replace("\t",'',$text);
$text=str_replace("\r",'',$text);
$text=str_replace('   ',' ',$text);
do {$text=str_replace("<br><br><br>","<br>",$text);} while (preg_match("/<br><br><br><br>/i",$text));
do {$text=str_replace("   "," ",$text);} while (preg_match("/   /i",$text));
$text=str_replace("\t",' ',$text);
$text=str_replace("\r",' ',$text);
$text=str_replace('   ',' ',$text);
$text=rtrim($text);
return $text; }

$frtname="Добавление анкеты";

if ($usercanadd!="0") {

if (isset($_GET['fid'])) {$fid=replacer($_GET['fid']);} else {exit(" <B>Ошибка скрипта или попытка взлома! fid</B>");}
if (isset($_GET['id'])) {$id=replacer($_GET['id']);} else {exit(" <B>Ошибка скрипта или попытка взлома! id </B>");}


if (!ctype_digit($fid)) {exit(" $back. Попытка взлома. Хакерам здесь не место.");}
if (!ctype_digit($id)) {exit("<B>$back. Попытка взлома. Хакерам здесь не место.</B>");}


if(!isset($_GET['event'])){  

include("$fskin/top.html");  

print"<br><form action=\"add.php?event=addanswer&fid=$fid&id=$id\" method=post enctype=\"multipart/form-data\" name=REPLIER>
<input type=hidden name=id value=$id>
<input type=hidden name=page value=0>
<input type=hidden name=zag value=\"$frtname\">

<table cellpadding=3 cellspacing=1 align=center width=800 class=forumline>
<tr><th class=thHead colspan=2 height=25><b>Добавление Студента</b></th></tr>

<tr>
<td class=row2 height=25><span class=gen>Фамилия Имя  Отчество</b></span></td>
<td class=row2><span class=genmed><input type=text name=famil class=post maxlength=$maxname size=27>
<input type=text name=name class=post maxlength=$maxname size=27>
<input type=text name=otch class=post maxlength=$maxname size=27></span></td>

</tr><tr>

<td class=row1 height=25><span class=gen>Дата рождения</span></td>

<td class=row1><span class=genmed>

	<input name='YetAnotherDate'>
	<input type='button' style='background: url('datepicker.jpg') no-repeat; width: 30px; border: 0px;' onclick='displayDatePicker('YetAnotherDate', false, 'dmy', '.');'>

</span></td>


</tr><tr>

<td class=row2 height=25><span class=gen>Форма обучения</span></td>
<td class=row2><span class=genmed>


<input type=radio name=sem value=Очная>Очная
<input type=radio name=sem value=Заочная>Заочная

</span></td>

</tr><tr>

<td class=row1 height=25><span class=gen>Номер Студенческого</span></td>
<td class=row1><span class=genmed><input type=text name=plan class=post maxlength=$maxname size=52></span></td>
</tr><tr>


<td class=row2 height=25><span class=gen>Номер Аттестата</span></td>
<td class=row2><span class=genmed><input type=text name=deyat class=post maxlength=$maxname size=52></span></td>

</tr><tr>

<td class=row1 height=25><span class=gen>Место Жительства:</span></td>
<td class=row1><span class=genmed><input type=text name=hobby class=post maxlength=$maxname size=52></span></td>

</tr><tr>

<td class=row2 height=25><span class=gen>Телефон Студента:</span></td>
<td class=row2><span class=genmed><input type=text name=gde class=post maxlength=$maxname size=52></span></td>

</tr><tr>

<td class=row1 height=25><span class=gen>Телефон Родителей:</span></td>
<td class=row1><span class=genmed><input type=text name=tel class=post maxlength=$maxname size=52></span></td>

</tr><tr class=row2>

<td>Прикрепить <B>фото</B></td><TD><input type=file name=file size=48 style='FONT-SIZE: 14px; WIDTH: 350px'></TD>

</tr><tr>

<td class=row1 valign=top><span class=genmed>О студенте:</span></td>

<td class=row2 valign=top><span class=gen><table width=245>
<TR><td colspan=9><span class=gen><textarea name=msg cols=60 rows=5 class=post></textarea></span></td>
</tr></table></span></td></tr>
<tr><td class=row1 colspan=2 align=center height=28><input type=submit tabindex=5 class=mainoption value=' Отправить '>&nbsp;&nbsp;&nbsp;<input type=reset tabindex=6 class=mainoption value=' Очистить '></td>
</tr></table></form>";

require ('images/bottom.html');









} else { 


if (replacer($_GET['event'])=="addanswer") {
$name=replacer($_POST['name']); $zag=replacer($_POST['zag']); $msg=replacer($_POST['msg']);

if (isset($_POST['who'])) {$who=replacer($_POST['who']);} else {$who="";}
if (isset($_POST['email'])) {$email=replacer($_POST['email']);} else {$email="";}
if (isset($_POST['page'])) {$page=replacer($_POST['page']);}
if (replacer($_GET['event'])=="addanswer") {$id=replacer($_POST['id']);}


$mainlines = file("$datadir/mainbase.dat"); $i=count($mainlines);
do {$i--; $dt = explode("|", replacer($mainlines[$i]));
if ($dt[0]==$fid) {$realfid=$i; if ($dt[1]=="razdel") {exit("попытка взлома");}} 
} while($i>0);

$back="<html><body bgcolor=#E5E5E5 text=#000000 link=#006699 vlink=#5493B4> <BR><center><B>Вернитесь <a href='javascript:history.back(1)'>назад</a>";

if (!isset($name) || strlen($name) > $maxname) {exit("$back ваше имя пустое, или превышает $maxname символов!</B></center>");}
if (!isset($msg) || strlen($msg) > $maxmsg) {exit("$back ваше сообщение пустое или превышает $maxmsg символов.</B></center>");}

{if (!isset($zag)) {exit("$back и введите заголовок!</B></center>");}}

if (!eregi("^([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)$", $email) and $email != "")
{exit("$back и введите корректный E-mail адрес!</B></center>");}

$tektime=time();
$email=substr($email,0,30);
$name=str_replace("|","I",$name);
$who=str_replace("|","I",$who);
$email=str_replace("|","I",$email);
$zag=str_replace("|","I",$zag);
$msg=str_replace("|","I",$msg);
$text="$name|$who|$email|$zag|$msg|$date|$time|$id||$tektime|";

if (strlen($name)>18) {$name=substr($name,0,18); $name.="..";}
if (strlen($zag)>24) {$zag=substr($zag,0,24); $zag.="..";}


$lines = file("$datadir/mainbase.dat");
$dt = explode("|", $lines[$realfid]);
if (replacer($_GET['event'])=="addtopic") {$dt[4]++;} $dt[5]++;
$txtdat="$dt[0]|$dt[1]|$dt[2]|$id|$dt[4]|$dt[5]|$name|$date|$time|$tektime|$zag|";

$fp=fopen("$datadir/mainbase.dat","a+");
flock ($fp,LOCK_EX); 
ftruncate ($fp,0);
for ($i=0;$i<=(sizeof($lines)-1);$i++) {if ($i==$realfid) {fputs($fp,"$txtdat\r\n");} else {fputs($fp,$lines[$i]);}}
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);

}


$name=replacer($_POST['name']);
$famil=replacer($_POST['famil']);
$otch=replacer($_POST['otch']);
$sem=replacer($_POST['sem']);
$plan=replacer($_POST['plan']);
$deyat=replacer($_POST['deyat']);
$msg=replacer($_POST['msg']);

if (isset($_POST['dayr'])) $dayr=replacer($_POST['dayr']); else $dayr="";
if (isset($_POST['hobby'])) $hobby=replacer($_POST['hobby']); else $hobby="";
if (isset($_POST['gde'])) $gde=replacer($_POST['gde']); else $gde="";
if (isset($_POST['tel'])) $tel=replacer($_POST['tel']); else $tel="";

if (isset($_POST['page'])) replacer($page=$_POST['page']); else $page=1;


$mainlines = file("$datadir/mainbase.dat"); $i=count($mainlines);
do {$i--; $dt=explode("|", replacer($mainlines[$i]));
if ($dt[0]==$fid) {$realfid=$i; if ($dt[1]=="razdel") {exit(" Попытка взлома.");}} // присваиваем $realfid - № п/п строки
} while($i>0);
if (!isset($realfid)) {print"Ошибка."; exit;}

if (!isset($name) || strlen($name) > $maxname || strlen($name) <1) {exit("$back Ваше <B>ИМЯ пустое, или превышает $maxname</B> символов!</B></center>");}



$valid_types=array("gif","jpg","png","jpeg");  
$max_file_size="200000"; 
$smwidth="120"; 
$smheight="150"; 

$fotoname = $_FILES['file']['name']; 
if (strlen($fotoname)>3) {
$fotosize=$_FILES['file']['size']; 

$ext = strtolower(substr($fotoname, 1 + strrpos($fotoname, ".")));
if (!in_array($ext, $valid_types)) {echo '<B>ФАЙЛ НЕ загружен.</B> Возможные причины:<BR>
- разрешена загрузка только файлов с такими расширениями: gif, jpg, jpeg, png<BR>
- Вы пытаетесь загрузить не графический файл;<BR>
- неверно введён адрес или выбран файл;</B><BR>'; exit;}


$findtchka=substr_count($fotoname, "."); if ($findtchka>1) {echo "ТОЧКА встречается в имени файла $findtchka раз(а). Это ЗАПРЕЩЕНО! <BR>\r\n";}


$bago="Извините. В имени ФАйла <B>запрещено</B> использовать .php, .html, .htm";
if (preg_match("/\.php/i",$fotoname))  {echo "Вхождение <B>\".php\"</B> найдено. $bago"; exit;}
if (preg_match("/\.html/i",$fotoname)) {echo "Вхождение <B>\".html\"</B> найдено. $bago"; exit;}
if (preg_match("/\.htm/i",$fotoname))  {echo "Вхождение <B>\".htm\"</B> найдено. $bago"; exit;}


if (!preg_match("/^[a-z0-9\.\-_]+\.(jpg|gif|png|)+$/is",$fotoname)) {print "Запрещено использовать РУССКИЕ буквы в имени файла!"; exit;}


if (file_exists("$datadir/$fotoname")) {print "Файл с таким именем уже существует на сервере! Измините имя на другое!"; exit;}

$fotoksize=round($fotosize/10.24)/100; 
$fotomax=round($max_file_size/10.24)/100; 
if ($fotoksize>$fotomax) {print"Вы превысили допустимый размер фото! <BR><B>Максимально допустимый</B> размер фото: <B>$fotomax </B>Кб.<BR> <B>Вы пытаетесь</B> загрузить изображение: <B>$fotoksize</B> Кб!"; exit;}

if   ($fotosize>"0" and $fotosize<$max_file_size) {
     copy($_FILES['file']['tmp_name'], $datadir."/".$fotoname);}
else { print "<B>Файл НЕ ЗАГРУЖЕН - ошибка СЕРВЕРА! Обратитесь к администратору!<B>"; exit;}

$size=getimagesize("$datadir/$fotoname");


if ($size[0]>$smwidth or $size[1]>$smheight) {
$smallfoto="sm-$fotoname";
require ('tumbmaker.php');
if (img_resize("$datadir/$fotoname", "$datadir/$smallfoto", $smwidth, $smheight))  $ok=1; else  echo '<font color=red><B>Ошибка МАСШАБИРОВАНИЯ фото! Поблемы с GD-библиотекой!</B></font> Обратитесь к Администратору';
} else {$smallfoto="$fotoname";}
} else {$smallfoto="nofoto.jpg"; $size[0]=""; $size[1]="";}


$z=1; do {$key=mt_rand(10000,99999); if (strlen($key)==5) {$z++;} } while ($z<1);
$tektime=time();

$text="$famil|$name|$otch|$dayr|$sem|$plan|$deyat|$hobby|$gde|$tel|$msg|$date|$time|$id|$tektime|$smallfoto|$size[0]|$size[1]|$key|$fotoname||||";
$text=replacer($text);
$exd=explode("|",$text); $famil=$exd[0]; $name=$exd[1]; $otch=$exd[2];


$fp=fopen("$datadir/$id.dat","a+");
flock ($fp,LOCK_EX);
fputs($fp,"$text\r\n");
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);

Header("Location: index.php?fid=$fid&id=$id&page=$page"); exit;}

} else {print"<br><br><center>Администратор запретил добавлять анкеты пользователям!<br><br>";} // if ($usercanadd!="0") {
?>
Как к этому скрипту можно прикрепить JavaScript и CSS скрипты??? :

Код: Выделить всё

<script src="datepicker.js" type="text/javascript" charset="UTF-8" language="javascript"></script>
<link rel="stylesheet" type="text/css" href="datepicker.css" />

Аватара пользователя
AgentSIB
Сообщения: 329
Зарегистрирован: 17.05.2010

Код: Выделить всё

include("$fskin/top.html");  
........
require ('images/bottom.html');
Вот в файл /top.html в <head> и нужно вставлять твои скрипты)
Frustra fit per plura quod potest fieri per pauciora © Закон "Бритвы Оккама"

Felixx
Сообщения: 4
Зарегистрирован: 24.11.2010
AgentSIB Выручил, Спасибо!

Ответить