stripslashes

PDO: stripslashes when getting results

天大地大妈咪最大 提交于 2019-12-06 07:33:57
问题 I am using PDO prepared statements so it's adding slashes when it's needed before inserting into the database. I was wondering the proper way to get the results and display it on the website without showing the slashes. Is it as easy as just using echo stripslashes($result->message); ? Here is what my queries look like: $database->query('INSERT INTO table_name (field1, field2, field3) VALUES (?, ?, ?)', array($value1, $value2, $value3)); Here is my query method: public function query($query,

PHP Security (strip_tags, htmlentities)

元气小坏坏 提交于 2019-12-05 08:55:39
I'm working in a personal project and besides using prepared statements, I would like to use every input as threat. For that I made a simple function. function clean($input){ if (is_array($input)){ foreach ($input as $key => $val){ $output[$key] = clean($val); } }else{ $output = (string) $input; if (get_magic_quotes_gpc()){ $output = stripslashes($output); } $output = htmlentities($output, ENT_QUOTES, 'UTF-8'); } return $output; } Is this enought or should I use to the following code? $output = mysqli_real_escape_string($base, $input); $output = strip_tags($output); Sorry this could be a silly

PDO: stripslashes when getting results

孤街浪徒 提交于 2019-12-04 12:57:29
I am using PDO prepared statements so it's adding slashes when it's needed before inserting into the database. I was wondering the proper way to get the results and display it on the website without showing the slashes. Is it as easy as just using echo stripslashes($result->message); ? Here is what my queries look like: $database->query('INSERT INTO table_name (field1, field2, field3) VALUES (?, ?, ?)', array($value1, $value2, $value3)); Here is my query method: public function query($query, $bind=null) { global $pdo; # Prepare Statment $this->statement = $this->pdo->prepare($query); # Execute

php---------字符串转义函数(addslashes,stripslashes)

一世执手 提交于 2019-12-04 09:03:43
在PHP中,有两个函数与字符串的转义有关,他们分别是 addslashes 和 stripslashes。 addslashes($string), 在指定的预定义字符前添加反斜杠 (\),用于为存储在数据库中的字符串以及数据库查询语句准备合适的字符串。 注释:默认情况下,PHP 指令 magic_quotes_gpc 为 on,对所有的 GET、POST 和 COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。 stripslashes($string),是addslashes()的反函数,用于删除由 addslashes() 函数添加的反斜杠以还原被转义的字符,也叫反转义,主要用于清理从数据库或 HTML 表单中取回的数据。 那么 addslashes 会对哪些字符进行转义呢,如下: 单引号 (') 双引号 (") 反斜杠 (\) NULL 另外,以单引号为定界符的字符串,支持两个转义字符: 单引号 (') 反斜杠 (\) 以双引号为定界符的字符串,支持下列转义: \n 换行 (LF 或 ASCII 字符 0x0A (10)) \r 回车 (CR 或 ASCII 字符 0x0D

Use JavaScript to stripslashes ? possible

风格不统一 提交于 2019-12-03 14:36:14
I'm using ajax to grab a URL. The problem is the URL has slashes in it and when the JQuery load takes place afterwords it will not load the page. AJAX success bit: success: function(data) { $('#OPTcontentpanel').load(data.OPTpermalink); PHP echo json_encode( array('OPTpermalink'=>$OPTpermalink,)); AND the response http:\/\/www.divethegap.com\/update\/options\/padi-open-water\/ So need to strip the slashes. I know how to do it in PHP but not in AJAX JavaScript. Any ideas? Marvellous ColBeseder A new answer to an old question: String.prototype.stripSlashes = function(){ return this.replace(/\\(.

What is the simplest way to remove a trailing slash from each parameter?

耗尽温柔 提交于 2019-12-03 02:54:24
问题 What is the simplest way to remove a trailing slash from each parameter in the '$@' array, so that rsync copies the directories by name? rsync -a --exclude='*~' "$@" "$dir" The title has been changed for clarification. To understand the comments and answer about multiple trailing slashes see the edit history. 回答1: You can use the ${parameter%word} expansion that is detailed here. Here is a simple test script that demonstrates the behavior: #!/bin/bash # Call this as: # ./test.sh one/ two/

What is the simplest way to remove a trailing slash from each parameter?

巧了我就是萌 提交于 2019-12-02 17:50:16
What is the simplest way to remove a trailing slash from each parameter in the '$@' array, so that rsync copies the directories by name? rsync -a --exclude='*~' "$@" "$dir" The title has been changed for clarification. To understand the comments and answer about multiple trailing slashes see the edit history. You can use the ${parameter%word} expansion that is detailed here . Here is a simple test script that demonstrates the behavior: #!/bin/bash # Call this as: # ./test.sh one/ two/ three/ # # Output: # one two three echo ${@%/} The accepted answer will trim ONE trailing slash. One way to

Antidote for magic_quotes_gpc()?

前提是你 提交于 2019-12-01 01:16:09
I've seen dozens of PHP snippets that go like this: function DB_Quote($string) { if (get_magic_quotes_gpc() == true) { $string = stripslashes($string); } return mysql_real_escape_string($string); } What happens if I call DB_Quote("the (\\) character is cool"); ? (Thanks jspcal!) Aren't we supposed to strip slashes only when get_magic_quotes_gpc() == true and the value originated from $_GET , $_POST or $_COOKIE superglobals? Yeah, I've seen dozens of PHP snippets like that, too. It's a bit sad. Magic quotes are an input issue. It has to be fixed at the input stage, by iterating the GET/POST

Antidote for magic_quotes_gpc()?

感情迁移 提交于 2019-11-30 20:44:05
问题 I've seen dozens of PHP snippets that go like this: function DB_Quote($string) { if (get_magic_quotes_gpc() == true) { $string = stripslashes($string); } return mysql_real_escape_string($string); } What happens if I call DB_Quote("the (\\) character is cool"); ? (Thanks jspcal!) Aren't we supposed to strip slashes only when get_magic_quotes_gpc() == true and the value originated from $_GET , $_POST or $_COOKIE superglobals? 回答1: Yeah, I've seen dozens of PHP snippets like that, too. It's a

PHP mysql_real_escape_string() -> stripslashes() leaving multiple slashes

假装没事ソ 提交于 2019-11-27 07:00:43
I'm having issues escaping/stripping strings with PHP/MySQL - there always seems to be redundant slashes. Let's take the following string as an example: <span style="text-decoration:underline;">underline</span> When adding a string to the database, I'm escaping it with mysql_real_escape_string() and the following gets stored in the database ( EDIT : checked this by querying the database directly with mysql app): <span style=\\\"text-decoration:underline;\\\">underline</span> When reading back out of the database, I'm passing the string through stripslashes() and the following is returned: