Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving Issues with Codeigniter App "The URI you submitted has disallowed characters."
    primarykey
    data
    text
    <p>I tried with almost all the methods posted in the thread.</p> <p>My url is like : www.example.com/twilio_sms/update_status‏ Many posts explained to edit </p> <pre><code>if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this-&gt;config-&gt;item('permitted_uri_chars'), '-'))."]+$|i", $str)) </code></pre> <p>to </p> <pre><code> if ( ! preg_match("|^[".($this-&gt;config-&gt;item('permitted_uri_chars'))."]+$|i", rawurlencode($str))) </code></pre> <p>but it leads to 404 error on that page.</p> <p>/system/core/URI.php :</p> <pre><code> &lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 * @filesource */ // ------------------------------------------------------------------------ /** * URI Class * * Parses URIs and determines routing * * @package CodeIgniter * @subpackage Libraries * @category URI * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/uri.html */ class CI_URI { var $keyval = array(); var $uri_string; var $segments = array(); var $rsegments = array(); /** * Constructor * * Simply globalizes the $RTR object. The front * loads the Router class early on so it's not available * normally as other classes are. * * @access public */ function __construct() { $this-&gt;config =&amp; load_class('Config', 'core'); log_message('debug', "URI Class Initialized"); } // -------------------------------------------------------------------- /** * Get the URI String * * @access private * @return string */ function _fetch_uri_string() { if (strtoupper($this-&gt;config-&gt;item('uri_protocol')) == 'AUTO') { // If the URL has a question mark then it's simplest to just // build the URI string from the zero index of the $_GET array. // This avoids having to deal with $_SERVER variables, which // can be unreliable in some environments if (is_array($_GET) &amp;&amp; count($_GET) == 1 &amp;&amp; trim(key($_GET), '/') != '') { $this-&gt;uri_string = key($_GET); return; } // Is there a PATH_INFO variable? // Note: some servers seem to have trouble with getenv() so we'll test it two ways $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); if (trim($path, '/') != '' &amp;&amp; $path != "/".SELF) { $this-&gt;uri_string = $path; return; } // No PATH_INFO?... What about QUERY_STRING? $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); if (trim($path, '/') != '') { $this-&gt;uri_string = $path; return; } // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? $path = str_replace($_SERVER['SCRIPT_NAME'], '', (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO')); if (trim($path, '/') != '' &amp;&amp; $path != "/".SELF) { // remove path and script information so we have good URI data $this-&gt;uri_string = $path; return; } // We've exhausted all our options... $this-&gt;uri_string = ''; } else { $uri = strtoupper($this-&gt;config-&gt;item('uri_protocol')); if ($uri == 'REQUEST_URI') { $this-&gt;uri_string = $this-&gt;_parse_request_uri(); return; } $this-&gt;uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); } // If the URI contains only a slash we'll kill it if ($this-&gt;uri_string == '/') { $this-&gt;uri_string = ''; } } // -------------------------------------------------------------------- /** * Parse the REQUEST_URI * * Due to the way REQUEST_URI works it usually contains path info * that makes it unusable as URI data. We'll trim off the unnecessary * data, hopefully arriving at a valid URI that we can use. * * @access private * @return string */ function _parse_request_uri() { if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') { return ''; } $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); if ($request_uri == '' OR $request_uri == SELF) { return ''; } $fc_path = FCPATH.SELF; if (strpos($request_uri, '?') !== FALSE) { $fc_path .= '?'; } $parsed_uri = explode("/", $request_uri); $i = 0; foreach(explode("/", $fc_path) as $segment) { if (isset($parsed_uri[$i]) &amp;&amp; $segment == $parsed_uri[$i]) { $i++; } } $parsed_uri = implode("/", array_slice($parsed_uri, $i)); if ($parsed_uri != '') { $parsed_uri = '/'.$parsed_uri; } return $parsed_uri; } // -------------------------------------------------------------------- /** * Filter segments for malicious characters * * @access private * @param string * @return string */ function _filter_uri($str) { if ($str != '' &amp;&amp; $this-&gt;config-&gt;item('permitted_uri_chars') != '' &amp;&amp; $this-&gt;config-&gt;item('enable_query_strings') == FALSE) { // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this-&gt;config-&gt;item('permitted_uri_chars'), '-'))."]+$|i", $str)) { show_error('The URI you submitted has disallowed characters.', 400); } } // Convert programatic characters to entities $bad = array('$', '(', ')', '%28', '%29'); $good = array('&amp;#36;', '&amp;#40;', '&amp;#41;', '&amp;#40;', '&amp;#41;'); return str_replace($bad, $good, $str); } // -------------------------------------------------------------------- /** * Remove the suffix from the URL if needed * * @access private * @return void */ function _remove_url_suffix() { if ($this-&gt;config-&gt;item('url_suffix') != "") { $this-&gt;uri_string = preg_replace("|".preg_quote($this-&gt;config-&gt;item('url_suffix'))."$|", "", $this-&gt;uri_string); } } // -------------------------------------------------------------------- /** * Explode the URI Segments. The individual segments will * be stored in the $this-&gt;segments array. * * @access private * @return void */ function _explode_segments() { foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this-&gt;uri_string)) as $val) { // Filter segments for security $val = trim($this-&gt;_filter_uri($val)); if ($val != '') { $this-&gt;segments[] = $val; } } } // -------------------------------------------------------------------- /** * Re-index Segments * * This function re-indexes the $this-&gt;segment array so that it * starts at 1 rather than 0. Doing so makes it simpler to * use functions like $this-&gt;uri-&gt;segment(n) since there is * a 1:1 relationship between the segment array and the actual segments. * * @access private * @return void */ function _reindex_segments() { array_unshift($this-&gt;segments, NULL); array_unshift($this-&gt;rsegments, NULL); unset($this-&gt;segments[0]); unset($this-&gt;rsegments[0]); } // -------------------------------------------------------------------- /** * Fetch a URI Segment * * This function returns the URI segment based on the number provided. * * @access public * @param integer * @param bool * @return string */ function segment($n, $no_result = FALSE) { return ( ! isset($this-&gt;segments[$n])) ? $no_result : $this-&gt;segments[$n]; } // -------------------------------------------------------------------- /** * Fetch a URI "routed" Segment * * This function returns the re-routed URI segment (assuming routing rules are used) * based on the number provided. If there is no routing this function returns the * same result as $this-&gt;segment() * * @access public * @param integer * @param bool * @return string */ function rsegment($n, $no_result = FALSE) { return ( ! isset($this-&gt;rsegments[$n])) ? $no_result : $this-&gt;rsegments[$n]; } // -------------------------------------------------------------------- /** * Generate a key value pair from the URI string * * This function generates and associative array of URI data starting * at the supplied segment. For example, if this is your URI: * * example.com/user/search/name/joe/location/UK/gender/male * * You can use this function to generate an array with this prototype: * * array ( * name =&gt; joe * location =&gt; UK * gender =&gt; male * ) * * @access public * @param integer the starting segment number * @param array an array of default values * @return array */ function uri_to_assoc($n = 3, $default = array()) { return $this-&gt;_uri_to_assoc($n, $default, 'segment'); } /** * Identical to above only it uses the re-routed segment array * */ function ruri_to_assoc($n = 3, $default = array()) { return $this-&gt;_uri_to_assoc($n, $default, 'rsegment'); } // -------------------------------------------------------------------- /** * Generate a key value pair from the URI string or Re-routed URI string * * @access private * @param integer the starting segment number * @param array an array of default values * @param string which array we should use * @return array */ function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') { if ($which == 'segment') { $total_segments = 'total_segments'; $segment_array = 'segment_array'; } else { $total_segments = 'total_rsegments'; $segment_array = 'rsegment_array'; } if ( ! is_numeric($n)) { return $default; } if (isset($this-&gt;keyval[$n])) { return $this-&gt;keyval[$n]; } if ($this-&gt;$total_segments() &lt; $n) { if (count($default) == 0) { return array(); } $retval = array(); foreach ($default as $val) { $retval[$val] = FALSE; } return $retval; } $segments = array_slice($this-&gt;$segment_array(), ($n - 1)); $i = 0; $lastval = ''; $retval = array(); foreach ($segments as $seg) { if ($i % 2) { $retval[$lastval] = $seg; } else { $retval[$seg] = FALSE; $lastval = $seg; } $i++; } if (count($default) &gt; 0) { foreach ($default as $val) { if ( ! array_key_exists($val, $retval)) { $retval[$val] = FALSE; } } } // Cache the array for reuse $this-&gt;keyval[$n] = $retval; return $retval; } // -------------------------------------------------------------------- /** * Generate a URI string from an associative array * * * @access public * @param array an associative array of key/values * @return array */ function assoc_to_uri($array) { $temp = array(); foreach ((array)$array as $key =&gt; $val) { $temp[] = $key; $temp[] = $val; } return implode('/', $temp); } // -------------------------------------------------------------------- /** * Fetch a URI Segment and add a trailing slash * * @access public * @param integer * @param string * @return string */ function slash_segment($n, $where = 'trailing') { return $this-&gt;_slash_segment($n, $where, 'segment'); } // -------------------------------------------------------------------- /** * Fetch a URI Segment and add a trailing slash * * @access public * @param integer * @param string * @return string */ function slash_rsegment($n, $where = 'trailing') { return $this-&gt;_slash_segment($n, $where, 'rsegment'); } // -------------------------------------------------------------------- /** * Fetch a URI Segment and add a trailing slash - helper function * * @access private * @param integer * @param string * @param string * @return string */ function _slash_segment($n, $where = 'trailing', $which = 'segment') { $leading = '/'; $trailing = '/'; if ($where == 'trailing') { $leading = ''; } elseif ($where == 'leading') { $trailing = ''; } return $leading.$this-&gt;$which($n).$trailing; } // -------------------------------------------------------------------- /** * Segment Array * * @access public * @return array */ function segment_array() { return $this-&gt;segments; } // -------------------------------------------------------------------- /** * Routed Segment Array * * @access public * @return array */ function rsegment_array() { return $this-&gt;rsegments; } // -------------------------------------------------------------------- /** * Total number of segments * * @access public * @return integer */ function total_segments() { return count($this-&gt;segments); } // -------------------------------------------------------------------- /** * Total number of routed segments * * @access public * @return integer */ function total_rsegments() { return count($this-&gt;rsegments); } // -------------------------------------------------------------------- /** * Fetch the entire URI string * * @access public * @return string */ function uri_string() { return $this-&gt;uri_string; } // -------------------------------------------------------------------- /** * Fetch the entire Re-routed URI string * * @access public * @return string */ function ruri_string() { return '/'.implode('/', $this-&gt;rsegment_array()).'/'; } } // END URI Class /* End of file URI.php */ /* Location: ./system/core/URI.php */ </code></pre> <p>/application/config/config.php</p> <pre><code> $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?'; $config['allow_get_array'] = TRUE; $config['enable_query_strings'] = FALSE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'; // experimental not currently in use </code></pre> <p>When i copied the url from browser it is like :</p> <pre><code>https://example.com/twilio_sms/update_status%E2%80%8F </code></pre> <p>And it should be like : </p> <pre><code>https://example.com/twilio_sms/update_status </code></pre> <p>Why it is adding extra characters ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload