PHP . SU
Программирование на PHP, MySQL и другие веб-технологии
Страниц (7): « 1 2 3 4 5 [6] 7 »
Найдено сообщений: 96
gigs
Отправлено: 07 Мая, 2012 - 14:06:12 • Тема: Защита сайта • Форум: Вопросы новичков
Ответов: 28 Просмотров: 36764
не понимаю у меня всеравно отсылает с ссылкой, у меня еще есть два файла, первый
submit.php
PHP:
скопировать код в буфер обмена
<?PHP
// Error reporting:
include "connect.php" ;
include "comment.class.php" ;
/*
/ This array is going to be populated with either
/ the data that was sent to the script, or the
/ error messages.
/*/
$validates = Comment:: validate ( $arr ) ;
if ( $validates ) {
/* Everything is OK, insert to database: */
mysql_query ( "INSERT INTO comments(name,url,email,body,pageid) VALUES (
'" . $arr [ 'name' ] . "',
'" . $arr [ 'url' ] . "',
'" . $arr [ 'email' ] . "',
'" . $arr [ 'body' ] . "',
'" . $arr [ 'pageid' ] . "'
)" ) ;
/*
/ The data in $arr is escaped for the mysql query,
/ but we need the unescaped variables, so we apply,
/ stripslashes to all the elements in the array:
/*/
$insertedComment = new Comment( $arr ) ;
/* Outputting the markup of the just-inserted comment: */
} else {
/* Outputtng the error messages */
}
?>
и второй script.js
CODE (
javascript ):
скопировать код в буфер обмена
$( document) .ready ( function ( ) {
/* The following code is executed once the DOM is loaded */
/* This flag will prevent multiple comment submits: */
var working = false ;
/* Listening for the submit event of the form: */
$( '#addCommentForm' ) .submit ( function ( e) {
e.preventDefault ( ) ;
if ( working) return false ;
working = true ;
$( '#submit' ) .val ( 'Working..' ) ;
$( 'span.error' ) .remove ( ) ;
/* Sending the form fileds to submit.php: */
$.post ( 'submit.php' , $( this ) .serialize ( ) , function ( msg) {
working = false ;
$( '#submit' ) .val ( 'Submit' ) ;
if ( msg.status ) {
/*
/ If the insert was successful, add the comment
/ below the last one on the page with a slideDown effect
/*/
$( msg.html ) .hide ( ) .insertBefore ( '#addCommentContainer' ) .slideDown ( ) ;
$( '#body' ) .val ( '' ) ;
}
else {
/*
/ If there were errors, loop through the
/ msg.errors object and display them on the page
/*/
$.each ( msg.errors , function ( k, v) {
$( 'label[for=' + k+ ']' ) .append ( '<span class="error">' + v+ '</span>' ) ;
} ) ;
}
} , 'json' ) ;
} ) ;
} ) ;
может в них еще что то надо менять ?
gigs
Отправлено: 07 Мая, 2012 - 13:47:23 • Тема: Защита сайта • Форум: Вопросы новичков
Ответов: 28 Просмотров: 36764
всеравно не работает, вот код другого файла обработки
comment.class.php
PHP:
скопировать код в буфер обмена
<?PHP
class Comment{
public function __construct( $row ) {
/*
/ The constructor
*/
$this -> data = $row ;
}
public function markup( ) {
/*
/ This method outputs the XHTML markup of the comment
*/
// Setting up an alias, so we don't have to write $this->data every time:
$d =& $this -> data ;
$link_open = '' ;
$link_close = '' ;
if ( $d [ 'url' ] ) {
// If the person has entered a URL when adding a comment,
// define opening and closing hyperlink tags
$link_open = '<a href="' . $d [ 'url' ] . '">' ;
$link_close = '</a>' ;
}
// Converting the time to a UNIX timestamp:
// Needed for the default gravatar image:
$url = 'http://' . dirname ( $_SERVER [ 'SERVER_NAME' ] . $_SERVER [ "REQUEST_URI" ] ) . '/img/default_avatar.gif' ;
return '
<div class="comment">
<div class="avatar">
' . $link_open . '
<!--img src="http://www.gravatar.com/avatar/' . md5 ( $d [ 'email' ] ) . '?size=50&default=' . urlencode ( $url ) . '" /--> ' . $link_close . '
</div>
<div class="name">' . $link_open . $d [ 'name' ] . $link_close . '</div>
<div class="date" title="Added at ' . date ( 'H:i \o\n d M Y' , $d [ 'dt' ] ) . '">' . date ( 'd M Y' , $d [ 'dt' ] ) . '</div> <p>' . $d [ 'body' ] . '</p>
</div>
' ;
}
public static function validate( & $arr ) {
/*
/ This method is used to validate the data sent via AJAX.
/
/ It return true/false depending on whether the data is valid, and populates
/ the $arr array passed as a paremter (notice the ampersand above) with
/ either the valid input data, or the error messages.
*/
// Using the filter_input function introduced in PHP 5.2.0
if ( ! ( $data [ 'email' ] = filter_input ( INPUT_POST
, 'email' , FILTER_VALIDATE_EMAIL
) ) ) { $errors [ 'email' ] = 'Please enter a valid Email.' ;
}
if ( ! ( $data [ 'url' ] = filter_input ( INPUT_POST
, 'url' , FILTER_VALIDATE_URL
) ) ) { // If the URL field was not populated with a valid URL,
// act as if no URL was entered at all:
$url = '' ;
}
// Using the filter with a custom callback function:
if ( ! ( $data [ 'body' ] = filter_input ( INPUT_POST
, 'body' , FILTER_CALLBACK
, array ( 'options' => 'Comment::validate_text' ) ) ) ) { $errors [ 'body' ] = 'Please enter a comment body.' ;
}
if ( ! ( $data [ 'name' ] = filter_input ( INPUT_POST
, 'name' , FILTER_CALLBACK
, array ( 'options' => 'Comment::validate_text' ) ) ) ) { $errors [ 'name' ] = 'Please enter a name.' ;
}
if ( ! ( $data [ 'pageid' ] = filter_input ( INPUT_POST
, 'page_id' , FILTER_VALIDATE_INT
) ) ) { $data [ 'pageid' ] = 0 ;
}
// If there are errors, copy the $errors array to $arr:
$arr = $errors ;
return false ;
}
// If the data is valid, sanitize all the data and copy it to $arr:
foreach ( $data as $k => $v ) {
}
// Ensure that the email is lower case:
return true ;
}
private static function validate_text( $str ) {
/*
/ This method is used internally as a FILTER_CALLBACK
*/
return false ;
// Encode all html special characters (<, >, ", & .. etc) and convert
// the new line characters to <br> tags:
// Remove the new line characters that are left
return $str ;
}
}
?>
в нем есть проверка email так она работает если неправильно введен email можно ли так само сделать и для проверки на ссылки? потомучто я делаю как вы пишите выше но ничего ни происходит, или можно ли эту проверку вставить в этот файл ?
gigs
Отправлено: 07 Мая, 2012 - 13:16:37 • Тема: Защита сайта • Форум: Вопросы новичков
Ответов: 28 Просмотров: 36764
что то ничего не происходит всеравно отсылает ссылки вида www[dot]site[dot]com и http://site[dot]com
вот файл формы
PHP:
скопировать код в буфер обмена
<?PHP
// Error reporting:
//id страницы
$pageID = ( isset ( $_GET [ 'id' ] ) ) ?
( int
) $_GET [ 'id' ] : 1 ; //по умолчанию первая страница имеет id=1
include "connect.php" ;
include "comment.class.php" ;
//Тут можно сделать свой запрос, взять контент сайта, заголовок, список для меню и т.п.
//Для примера просто выводим из массива.
//Далее работа с комментариями
$result = mysql_query ( "SELECT * FROM comments WHERE pageid='$pageID ' ORDER BY id ASC" ) ; $comments [ ] = new Comment( $row ) ;
}
header ( 'Content-Type: text/html; charset=utf-8' ) ; ?>
<!DOCTYPE html>
<html>
<head>
<title>Страница <?= $pageID ?> </title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="main">
<div>
<?PHP
foreach ( $comments as $c ) {
echo $c -> markup ( ) ;
}
?>
</div>
<div id="addCommentContainer">
<p>Оставить комментарий</p>
<form id="addCommentForm" method="post" action="1.php">
<div>
<label for="name">Ваше имя</label>
<input type="text" name="name" id="name" />
<label for="email">Ваш Email</label>
<input type="text" name="email" id="email" />
<label for="body">Текс комментария</label>
<textarea name="body" id="body" cols="20" rows="5"></textarea>
<input type="hidden" name="page_id" value="<?= $pageID ?> " />
<input type="submit" id="submit" value="Отправить" />
</div>
</form>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
а вот файл обработчик 1.php
(Добавление)
может это из за того что уменя два файла обработчика, первый у меня это 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
потом вставил в action но ничего не происходит, что не так помогите ?
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:
скопировать код в буфер обмена
<?PHP
// Error reporting:
//id страницы
$pageID = ( isset ( $_GET [ 'id' ] ) ) ?
( int
) $_GET [ 'id' ] : 1 ; //по умолчанию первая страница имеет id=1
include "connect.php" ;
include "comment.class.php" ;
//Далее работа с комментариями
$result = mysql_query ( "SELECT * FROM comments WHERE pageid='$pageID ' ORDER BY id ASC" ) ; $comments [ ] = new Comment( $row ) ;
}
header ( 'Content-Type: text/html; charset=utf-8' ) ; ?>
<!DOCTYPE html>
<html>
<head>
<title>Страница <?= $pageID ?> </title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="main">
<div>
<?PHP
foreach ( $comments as $c ) {
echo $c -> markup ( ) ;
}
?>
</div>
<div id="addCommentContainer">
<p>Оставить комментарий</p>
<form id="addCommentForm" method="post" action="">
<div>
<label for="name">Ваше имя</label>
<input type="text" name="name" id="name" />
<label for="email">Ваш Email</label>
<input type="text" name="email" id="email" />
<label for="body">Текс комментария</label>
<textarea name="body" id="body" cols="20" rows="5"></textarea>
<input type="hidden" name="page_id" value="<?= $pageID ?> " />
<input type="submit" id="submit" value="Отправить" />
</div>
</form>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
подскажите куда мне нужно это добавить?
gigs
Отправлено: 03 Мая, 2012 - 15:10:43 • Тема: Защита сайта • Форум: Вопросы новичков
Ответов: 28 Просмотров: 36764
Спасибо, а эту функцию
нужно ставить там где форма после подключения к базе или как? а то я еще ни разу не работал с такой функцией.
(Добавление)
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 или чтото в этом роде.
Страниц (7): « 1 2 3 4 5 [6] 7 »
Powered by ExBB FM 1.0 RC1. InvisionExBB