filter-var

Why FILTER_VALIDATE_URL return FALSE for only this url?

末鹿安然 提交于 2020-01-24 13:54:16
问题 i have the following code: $url = "http://icons3.iconfinder.netdna-cdn.com/data/icons/pool/poolbird.png"; if (filter_var ($url, FILTER_VALIDATE_URL) === FALSE) { echo "Invalid Url"; exit; } else { echo "Works!"; } This displays: invalid url (FALSE) for the above url, but not for other simpler urls. Is this a bug? you can even access the image. And the most important is what's the solution for this? Thanks 回答1: PHP < 5.2.13 contains a bug in FILTER_VALIDATE_URL that considers urls containing

Sanitize JSON with php

↘锁芯ラ 提交于 2020-01-10 02:50:45
问题 I always use filter_var($var, FILTER, FLAG); when I get data from $_GET, $_POST and so on, but now this data is a JSON string but I didn't find any filter to sanitize JSON. Anyone know how to implement this filter? PHP filter_var(): http://php.net/manual/en/function.filter-var.php PHP FILTER CONST: http://php.net/manual/en/filter.filters.sanitize.php 回答1: Parse the JSON first into a PHP array and then filter each value in the array as you do with regular request content, you could map the

PHP FILTER_VALIDATE_EMAIL does not work correctly

让人想犯罪 __ 提交于 2019-12-28 05:30:07
问题 I'm using PHP 5.3.10. This is the code: <?php $email = "test@example.c"; if (filter_var($email, FILTER_VALIDATE_EMAIL)) echo "Email: ".$email." correct"; else echo "email not correct"; ?> It returns: "Email: test@example.c correct. I think that a top level domain with only one character is not correct (I'm not aware of one-character-length TLD according to this list: http://data.iana.org/TLD/tlds-alpha-by-domain.txt ). So, FILTER_VALIDATE_EMAIL filter is working correctly or not? 回答1:

PHP filter_var: How to make sure the user provides correct data types - true or false only

筅森魡賤 提交于 2019-12-25 05:22:29
问题 I want to compare two arrays, one is set by default and another by user input. When I have set a boolean value only in the default so I want to make sure the user won't use string or number. for instance, 'truex' or '1' is not acceptable. Below is my sample of code, $default = array( "randomise" => false, "id" => null ); $config = array( "randomise" => truex ); function process_array($default,$config) { # Loop the array. foreach($default as $key => $value) { if ((filter_var($default[$key],

Filter var for calling a shellscript with system on php

末鹿安然 提交于 2019-12-11 11:18:21
问题 i need to filter those var to call system in php and execute a shell script. What filter_var SANITIZE macro i need to use to remove ";" or problems during shell execution? Like unwanted chars..etc..etc This is my code testing example, now i've hardcoded the var for testing.. Thanks! $ragionesociale = $_GET["ragionesociale"]; /* Alphanumeric with spaces next trimmed*/ $api = $_GET["ragionesociale"]; /* Uri with space encoded*/ $sito = $_GET["sito"]; /* Uri with space encoded*/ $meta = $_GET[

Intern working for Indian NGO - Help with PHP 4, advising staff

假装没事ソ 提交于 2019-12-11 04:05:41
问题 For the past three months I've been working for an Indian NGO, doing some volunteer work in the field but also trying to improve their website, which needs a ton of work. Recently I've been trying to fix the "subscribe to newsletter" button, which is broken. I used filter_var to filter the email input, but when I tried to test this out I got an error. Then I learned that the web host is still using php version 4.3.2 and register_globals is turned on. I've mentioned that they should upgrade

php filter var returning a wrong result

假如想象 提交于 2019-12-10 18:26:05
问题 I wanted to use the php filer_var function but it's returning a wrong result, it seems that it doesn't take into account the range: $v = 54; $int_opts = array ( 'min_range' => 0, 'max_range' => 24 ); if ( filter_var($v, FILTER_VALIDATE_INT, $int_opts) ) echo 'an integer'; else echo 'not an integer'; This shouldn't be an integer as 54 is not between 0 and 24, but it returns true and echoes "an integer". What's the problem here? Thanks. 回答1: The "options" array needs to have a member named

PHP - Filter_var alternative?

戏子无情 提交于 2019-12-10 16:35:40
问题 I built a php script to output data posted in a form, but I ran into a problem. The server the website is going to run on, runs PHP 5.1.6. This version of PHP does not support filter_var. I need to know an alternative on short term (preferably yesterday), and can't find something straight forward on Google or Stack Overflow. Mayhap someone here ran into the same issue in the past and has a quick fix for me? This code: $email= filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $answer= filter

Editing form to sanitize/validate phone number

旧巷老猫 提交于 2019-12-10 03:41:38
问题 I have very limited experience with PHP and I'm really hoping someone can help me. What I want to do is sanitize/validate the phone number input so that only numbers are allowed. I think I need to use FILTER_SANITIZE_NUMBER_INT but I'm not sure where or how to use it. Here is my code: <?php // Replace the email address with the one that should receive the contact form inquiries. define('TO_EMAIL', '########'); $aErrors = array(); $aResults = array(); /* Functions */ function stripslashes_if

Validating non-private IP addresses with PHP

爷,独闯天下 提交于 2019-12-09 09:10:23
问题 I'm trying to check whether or not an IP address is an internal-only (i.e. private) IP, but I'm getting a curious result: filter_var('173.194.66.94', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE); // returns 173.194.66.94 filter_var('192.168.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE); // returns false filter_var('127.0.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE); // returns 127.0.0.1? Surely 127.0.0.1 counts as a private IP? I found this bug report from 2010 which reports