PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи

Страниц (7): « 1 2 3 4 5 [6] 7 »

> Найдено сообщений: 96
gigs Отправлено: 07 Мая, 2012 - 14:33:18 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
на 101 строке дримвивер находит ошибку
gigs Отправлено: 07 Мая, 2012 - 14:06:12 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
не понимаю у меня всеравно отсылает с ссылкой, у меня еще есть два файла, первый
submit.php
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2.  
  3. // Error reporting:
  4. error_reporting(E_ALL^E_NOTICE);
  5.  
  6. include "connect.php";
  7. include "comment.class.php";
  8.  
  9. /*
  10. /       This array is going to be populated with either
  11. /       the data that was sent to the script, or the
  12. /       error messages.
  13. /*/
  14.  
  15. $arr=array();
  16. $validates = Comment::validate($arr);
  17.  
  18. if($validates){
  19.         /* Everything is OK, insert to database: */
  20.  
  21.         mysql_query("INSERT INTO comments(name,url,email,body,pageid)
  22.                                         VALUES (
  23.                                                 '".$arr['name']."',
  24.                                                 '".$arr['url']."',
  25.                                                 '".$arr['email']."',
  26.                                                 '".$arr['body']."',
  27.                                                 '".$arr['pageid']."'
  28.                                         )");
  29.  
  30.         $arr['dt']=date('r',time());
  31.         $arr['id']=mysql_insert_id();
  32.  
  33.         /*
  34.         /       The data in $arr is escaped for the mysql query,
  35.         /       but we need the unescaped variables, so we apply,
  36.         /       stripslashes to all the elements in the array:
  37.         /*/
  38.  
  39.         $arr=array_map('stripslashes',$arr);
  40.  
  41.         $insertedComment=new Comment($arr);
  42.  
  43.         /* Outputting the markup of the just-inserted comment: */
  44.  
  45.         echo json_encode(array('status'=>1,'html'=>$insertedComment->markup()));
  46.  
  47. }else{
  48.         /* Outputtng the error messages */
  49.         echo '{"status":0,"errors":'.json_encode($arr).'}';
  50. }
  51.  
  52. ?>
  53.  


и второй script.js
CODE (javascript):
скопировать код в буфер обмена
  1. $(document).ready(function(){
  2.         /* The following code is executed once the DOM is loaded */
  3.        
  4.         /* This flag will prevent multiple comment submits: */
  5.         var working = false;
  6.        
  7.         /* Listening for the submit event of the form: */
  8.         $('#addCommentForm').submit(function(e){
  9.  
  10.                 e.preventDefault();
  11.                 if(working) return false;
  12.                
  13.                 working = true;
  14.                 $('#submit').val('Working..');
  15.                 $('span.error').remove();
  16.                
  17.                 /* Sending the form fileds to submit.php: */
  18.                 $.post('submit.php',$(this).serialize(),function(msg){
  19.  
  20.                         working = false;
  21.                         $('#submit').val('Submit');
  22.                        
  23.                         if(msg.status){
  24.  
  25.                                 /*
  26.                                 /       If the insert was successful, add the comment
  27.                                 /       below the last one on the page with a slideDown effect
  28.                                 /*/
  29.  
  30.                                 $(msg.html).hide().insertBefore('#addCommentContainer').slideDown();
  31.                                 $('#body').val('');
  32.                         }
  33.                         else {
  34.  
  35.                                 /*
  36.                                 /       If there were errors, loop through the
  37.                                 /       msg.errors object and display them on the page
  38.                                 /*/
  39.                                
  40.                                 $.each(msg.errors,function(k,v){
  41.                                         $('label[for='+k+']').append('<span class="error">'+v+'</span>');
  42.                                 });
  43.                         }
  44.                 },'json');
  45.  
  46.         });
  47.        
  48. });

может в них еще что то надо менять ?
gigs Отправлено: 07 Мая, 2012 - 13:47:23 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
всеравно не работает, вот код другого файла обработки
comment.class.php
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. class Comment{
  3.         private $data=array();
  4.  
  5.         public function __construct($row){
  6.                 /*
  7.                 /       The constructor
  8.                 */
  9.                 $this->data=$row;
  10.         }
  11.  
  12.         public function markup(){
  13.                 /*
  14.                 /       This method outputs the XHTML markup of the comment
  15.                 */
  16.  
  17.                 // Setting up an alias, so we don't have to write $this->data every time:
  18.                 $d=&$this->data;
  19.  
  20.                 $link_open='';
  21.                 $link_close='';
  22.  
  23.                 if($d['url']){
  24.                         // If the person has entered a URL when adding a comment,
  25.                         // define opening and closing hyperlink tags
  26.  
  27.                         $link_open='<a href="'.$d['url'].'">';
  28.                         $link_close='</a>';
  29.                 }
  30.  
  31.                 // Converting the time to a UNIX timestamp:
  32.                 $d['dt']=strtotime($d['dt']);
  33.  
  34.                 // Needed for the default gravatar image:
  35.                 $url='http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';
  36.  
  37.                 return '
  38.                         <div class="comment">
  39.                                 <div class="avatar">
  40.                                         '.$link_open.'
  41.                                         <!--img src="http://www.gravatar.com/avatar/'.md5($d['email']).'?size=50&default='.urlencode($url).'" /-->
  42.                                         '.$link_close.'
  43.                                 </div>
  44.  
  45.                                 <div class="name">'.$link_open.$d['name'].$link_close.'</div>
  46.                                 <div class="date" title="Added at '.date('H:i \o\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
  47.                                 <p>'.$d['body'].'</p>
  48.                         </div>
  49. ';
  50.         }
  51.  
  52.         public static function validate(&$arr){
  53.                 /*
  54.                 /       This method is used to validate the data sent via AJAX.
  55.                 /
  56.                 /       It return true/false depending on whether the data is valid, and populates
  57.                 /       the $arr array passed as a paremter (notice the ampersand above) with
  58.                 /       either the valid input data, or the error messages.
  59.                 */
  60.  
  61.                 $errors=array();
  62.                 $data=array();
  63.  
  64.                 // Using the filter_input function introduced in PHP 5.2.0
  65.  
  66.                 if(!($data['email']=filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL))){
  67.                         $errors['email']='Please enter a valid Email.';
  68.                 }
  69.  
  70.                 if(!($data['url']=filter_input(INPUT_POST,'url',FILTER_VALIDATE_URL))){
  71.                         // If the URL field was not populated with a valid URL,
  72.                         // act as if no URL was entered at all:
  73.                         $url='';
  74.                 }
  75.  
  76.                 // Using the filter with a custom callback function:
  77.  
  78.                 if(!($data['body']=filter_input(INPUT_POST,'body',FILTER_CALLBACK,array('options'=>'Comment::validate_text')))){
  79.                         $errors['body']='Please enter a comment body.';
  80.                        
  81.                 }
  82.  
  83.                 if(!($data['name']=filter_input(INPUT_POST,'name',FILTER_CALLBACK,array('options'=>'Comment::validate_text')))){
  84.                         $errors['name']='Please enter a name.';
  85.                 }
  86.  
  87.                 if(!($data['pageid']=filter_input(INPUT_POST,'page_id',FILTER_VALIDATE_INT))){
  88.                         $data['pageid']=0;
  89.                 }
  90.  
  91.                 if(!empty($errors)){
  92.                         // If there are errors, copy the $errors array to $arr:
  93.                         $arr=$errors;
  94.                         return false;
  95.                 }
  96.                 // If the data is valid, sanitize all the data and copy it to $arr:
  97.                 foreach($data as $k=>$v){
  98.                         $arr[$k]=mysql_real_escape_string($v);
  99.                 }
  100.                 // Ensure that the email is lower case:
  101.                 $arr['email']=strtolower(trim($arr['email']));
  102.                 return true;
  103.         }
  104.  
  105.         private static function validate_text($str){
  106.                 /*
  107.                 /       This method is used internally as a FILTER_CALLBACK
  108.                 */
  109.                 if(mb_strlen($str,'utf8')<1)
  110.                         return false;
  111.  
  112.                 // Encode all html special characters (<, >, ", & .. etc) and convert
  113.                 // the new line characters to <br> tags:
  114.                 $str=nl2br(htmlspecialchars($str));
  115.                 // Remove the new line characters that are left
  116.                 $str=str_replace(array(chr(10),chr(13)),'',$str);
  117.                 return $str;
  118.         }
  119. }
  120. ?>
  121.  
  122.  

в нем есть проверка email так она работает если неправильно введен email можно ли так само сделать и для проверки на ссылки? потомучто я делаю как вы пишите выше но ничего ни происходит, или можно ли эту проверку вставить в этот файл ?
gigs Отправлено: 07 Мая, 2012 - 13:16:37 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
что то ничего не происходит всеравно отсылает ссылки вида www[dot]site[dot]com и http://site[dot]com
вот файл формы
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2.  
  3. // Error reporting:
  4. error_reporting(E_ALL^E_NOTICE);
  5. //id страницы
  6. $pageID=(isset($_GET['id']))?(int)$_GET['id']:1;//по умолчанию первая страница имеет id=1
  7.  
  8. include "connect.php";
  9. include "comment.class.php";
  10.  
  11. //Тут можно сделать свой запрос, взять контент сайта, заголовок, список для меню и т.п.
  12. //Для примера просто выводим из массива.
  13.  
  14.  
  15.  
  16. //Далее работа с комментариями
  17. $comments=array();
  18. $result=mysql_query("SELECT * FROM comments WHERE pageid='$pageID' ORDER BY id ASC");
  19. while($row=mysql_fetch_assoc($result)){
  20.         $comments[]=new Comment($row);
  21. }
  22.  
  23. header('Content-Type: text/html; charset=utf-8');
  24. ?>
  25. <!DOCTYPE html>
  26. <html>
  27. <head>
  28. <title>Страница <?=$pageID?></title>
  29. <link rel="stylesheet" type="text/css" href="styles.css" />
  30. </head>
  31. <body>
  32. <div id="main">
  33. <div>
  34.        
  35. <?PHP
  36. foreach($comments as $c){
  37.         echo $c->markup();
  38. }
  39. ?>
  40. </div>
  41.  
  42. <div id="addCommentContainer">
  43.         <p>Оставить комментарий</p>
  44.         <form id="addCommentForm" method="post" action="1.php">
  45.                 <div>
  46.                         <label for="name">Ваше имя</label>
  47.                         <input type="text" name="name" id="name" />
  48.  
  49.                         <label for="email">Ваш Email</label>
  50.                         <input type="text" name="email" id="email" />
  51.  
  52.                        
  53.  
  54.                        
  55.     <label for="body">Текс комментария</label>
  56.                         <textarea name="body" id="body" cols="20" rows="5"></textarea>
  57.  
  58.                         <input type="hidden" name="page_id" value="<?=$pageID?>" />
  59.  
  60.                         <input type="submit" id="submit" value="Отправить" />
  61.                 </div>
  62.         </form>
  63. </div>
  64.  
  65. </div>
  66. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  67. <script type="text/javascript" src="script.js"></script>
  68. </body>
  69. </html>


а вот файл обработчик 1.php
PHP:
скопировать код в буфер обмена
  1. <?
  2. $text=$_POST['body'];
  3. if(!preg_match("^|www.[\w]+.[\w]{1,4}|^",$text))
  4. {
  5.     echo "Ссылки запрещены!";
  6. }
  7. ?>

(Добавление)
может это из за того что уменя два файла обработчика, первый у меня это comment.class.php, а второй я создал этот 1.php чтобы находило ссылки, может из за этого ?
gigs Отправлено: 07 Мая, 2012 - 12:29:56 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
в action я указал файл 1.php но вот не знаю как в нем сделать эту проверку, как ее вызвать внутри цикла if чтобы оно проверяло текст на наличие ссылок и потом если найдет ссылку, блокировало отправку данных и выводило сообщение "Ссылки запрещены"
gigs Отправлено: 06 Мая, 2012 - 20:46:03 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
что то у меня не получается, как мне правиль но сделать файл-обработчик формы, я сделал так:
имя файла 1.php
PHP:
скопировать код в буфер обмена
  1. <? function delLinks($body)
  2.     {
  3.         return preg_replace('|www.[\w]+.[\w]{1,4}|','Ссылки запрещены!',$body);
  4.     }
  5.         ?>

потом вставил в action но ничего не происходит, что не так помогите ?
gigs Отправлено: 05 Мая, 2012 - 20:00:35 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
Или это в файл обработки нужно ставить ?
gigs Отправлено: 03 Мая, 2012 - 20:30:40 • Тема: не работает сервер • Форум: Вопросы новичков

Ответов: 27
Просмотров: 784
евгений777, установите себе XAMPP и не мучайтесь, там сразу все само установится
вот ссылка ***.apachefriends.org/en/xampp.html вместо *** пишеш www.
gigs Отправлено: 03 Мая, 2012 - 16:01:47 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
я извеняюсь но вот код моей формы
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2.  
  3. // Error reporting:
  4. error_reporting(E_ALL^E_NOTICE);
  5. //id страницы
  6. $pageID=(isset($_GET['id']))?(int)$_GET['id']:1;//по умолчанию первая страница имеет id=1
  7.  
  8. include "connect.php";
  9. include "comment.class.php";
  10.  
  11.  
  12.  
  13.  
  14.  
  15. //Далее работа с комментариями
  16. $comments=array();
  17. $result=mysql_query("SELECT * FROM comments WHERE pageid='$pageID' ORDER BY id ASC");
  18. while($row=mysql_fetch_assoc($result)){
  19.         $comments[]=new Comment($row);
  20. }
  21.  
  22. header('Content-Type: text/html; charset=utf-8');
  23. ?>
  24. <!DOCTYPE html>
  25. <html>
  26. <head>
  27. <title>Страница <?=$pageID?></title>
  28. <link rel="stylesheet" type="text/css" href="styles.css" />
  29. </head>
  30. <body>
  31. <div id="main">
  32. <div>
  33. <?PHP
  34. foreach($comments as $c){
  35.         echo $c->markup();
  36. }
  37. ?>
  38. </div>
  39.  
  40. <div id="addCommentContainer">
  41.         <p>Оставить комментарий</p>
  42.         <form id="addCommentForm" method="post" action="">
  43.                 <div>
  44.                         <label for="name">Ваше имя</label>
  45.                         <input type="text" name="name" id="name" />
  46.  
  47.                         <label for="email">Ваш Email</label>
  48.                         <input type="text" name="email" id="email" />
  49.  
  50.                        
  51.  
  52.                         <label for="body">Текс комментария</label>
  53.                         <textarea name="body" id="body" cols="20" rows="5"></textarea>
  54.  
  55.                         <input type="hidden" name="page_id" value="<?=$pageID?>" />
  56.  
  57.                         <input type="submit" id="submit" value="Отправить" />
  58.                 </div>
  59.         </form>
  60. </div>
  61.  
  62. </div>
  63. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  64. <script type="text/javascript" src="script.js"></script>
  65. </body>
  66. </html>

подскажите куда мне нужно это добавить?
gigs Отправлено: 03 Мая, 2012 - 15:10:43 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
Спасибо, а эту функцию
PHP:
скопировать код в буфер обмена
  1.     function delLinks($text)
  2.     {
  3.         return preg_replace('|www.[\w]+.[\w]{1,4}|','Ссылки запрещены!',$text);
  4.     }

нужно ставить там где форма после подключения к базе или как? а то я еще ни разу не работал с такой функцией.
(Добавление)
nordghost пишет:
тебе нужно чтобы ссылки не были ссылками или просто чтобы не отображались?

чтобы не были ссылками, что бы с них нельзя было заходит на другой сайт.
(Добавление)
и еще у меня нету файла .htacces, как его можно создать и подключить к сайту ?
gigs Отправлено: 02 Мая, 2012 - 17:19:27 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
А что если будет стоять тег a href то это не будет считатся за ссылку?
gigs Отправлено: 02 Мая, 2012 - 17:07:48 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
Что то я неочень понял, а можите привести пример с кодом?
gigs Отправлено: 02 Мая, 2012 - 17:00:21 • Тема: Защита сайта • Форум: Вопросы новичков

Ответов: 28
Просмотров: 36764
Скажите пожалуйста, есть ли какой нибуть срособ для защиты формы комментариев от ссылок? Например чтобы когда пользователь вводил www[dot]сайт[dot]com то после отправки появлялось ***.сайт.com чтобы не было вот этих www или чтото в этом роде.
gigs Отправлено: 25 Апреля, 2012 - 19:33:49 • Тема: Повторяются комментарии на страницах • Форум: Вопросы новичков

Ответов: 15
Просмотров: 543
что нужно поменять их местами так:
PHP:
скопировать код в буфер обмена
  1. $pageID = (isset($_GET['id'])) ? (int)$_GET['id'] : 'none';
  2. $result = mysql_query("SELECT * FROM comments where PageID = '" . $pageID . "' ORDER BY id ASC");
  3.  
gigs Отправлено: 25 Апреля, 2012 - 17:32:38 • Тема: Повторяются комментарии на страницах • Форум: Вопросы новичков

Ответов: 15
Просмотров: 543
Спасибо, а как правильно должно быть что то я ни как не могу понять ?

Страниц (7): « 1 2 3 4 5 [6] 7 »
Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB