Part of the EllisLab Network
   
1 of 2
1
IMPLEMENTED: get() method from input class, better routing without mod_rewrite, bug fix for CI_Input methods
Posted: 13 December 2006 08:20 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

I’ve extended the Input class with a get() method, because there’s no good reason to kill query strings, just because they can be abused.  Remember that “Code Igniter is right for you if... [you] want a framework that does not require you to adhere to restrictive coding rules.”

I don’t know how many people are actually using query strings with CI, because it doesn’t work well, but I’ve got them covered as well with a router change that allows segment data, and the use of the URL helper because you can use URIs like: ‘/index.php?/controller/method/segment?query=foo’

There’s also a bug (when the magic quotes misfeature is enabled) in the CI_Input methods that run stripslashes on the keys of superglobals when they are retrieved, but not the values... a big problem when the database class once-again escapes strings in SQL statements.

To start using this fix/extension, download this ZIP file.  This compressed application folder contains the required MY_Input and MY_Router libraries, an example set of additions to config.php, as well as a basic controller (Ir—Input/Routing) and view for testing.

UPDATE: The input class also now has _list, functions for each method, e.g. get_list().  It accepts a variable length argument list, and there are three ways to use it:

Usage 1: get_list(array(‘username’, ‘password’, ‘passconf’)[, true])
arg1 (array): Required.  List of keys to retrieve values from.
arg2 (bool): Optional, default FALSE. Toggle cross-site scripting filter

Usage 2: get_list(‘username,password,passconf’[, true])
arg1 (string): Required. A comma-delimited list of keys to retrieve values from.
arg2 (bool): Optional, default FALSE.  Toggle cross-site scripting filter

Usage 3: get_list(‘username’, ‘password’, ‘passconf’[, true])
arg1… Keys to retrieve values from
lastarg: Optional, default FALSE.  Toggle cross-site scripting filter

UPDATE: Query string routing is an OPTION.  It was a simple change that came along for the ride in fixing the input class.  One further update I may end up making is to eliminate the query string routing config option and just detect the setting based on the last character of index page.

UPDATE #34480227: The current version does not try to reproduce the original code, unlike the original proof-of-concept.  It also solves the bug that causes CI to not report rsegment #2 when the index method is used.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 14 December 2006 09:16 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  173
Joined  11-29-2006

I personally don’t have any use for your work at this time, but I briefly looked over the code and can recommend one improvement which I think anyone using your work would enjoy.

function get($index, $xss_clean = false)
    
{
        $result
= (isset($_GET[$index])) ? $this->_gpc($_GET[$index], $xss_clean) : false;
        return
$result;
    
}

        
// Replace with this

    
function get ( $index, $xss_clean = false )
    
{
        $indexes
= array();

        
// If its an array of indexs, handle them recursively
        
if (is_array($index) && count($index) > 0)
        
{
            
for ($i = 0; $i < count($index); $i ++)
            
{
                $this
->get($index[$i], $xss_clean);
            
}
        }

        
// If its an individual index, save the value
        
else
        
{
            $result
= (isset($_GET[$index])) ? $this->_gpc($_GET[$index], $xss_clean) : false;
            
$indexes[$index] = $result;
        
}

        
return $indexes;
    
}
    
        
// use it like: $get_array = $this->input->get(array('var1', 'var2', 'var3', var4'), true);

I haven’t tested this code, but basically it would allow the user to fetch multiple $_GET values at once, instead of individually. If I have five values I want from the query string, I don’t want to make five seperate calls. Hope this helps.

Profile
 
 
Posted: 14 December 2006 10:49 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

(This is where I posted about a variable argument list version, but now I have something better in the works)

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 14 December 2006 11:13 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

Hate to say it, but I’ve one-upped you by supporting arrays, a string of comma-delimited values, OR a variable-length array of strings.  It does add a few lines of code… not many… but I’ve made them separate functions, e.g. get_list().

Same link:
http://champs.name/ci/input/libraries.zip

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 14 December 2006 12:58 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  173
Joined  11-29-2006

Well I don’t care that you ‘one-upped’ me, I just gave you a simple example off the top of my head smile Good work.

Profile
 
 
Posted: 22 January 2007 04:40 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  109
Joined  05-25-2006

@champs: I have got errors using your classes. The patch from nvidiafx works for me.
http://www.codeigniter.com/forums/viewthread/2659

——
@champs: Sorry, I have deleted my temp project with your classes. There were errors about wrong segments.
——

Why i prefer the nvidiafx’s Input and Router classes?
Because his solution works without

$config['index_page'] = "index.php?";


It is compatible with “standard” CI URLs

/index.php/controller/method/segment?query=foo


No question mark needed.

 Signature 

CI 1.5 on WAMP (W2k Pro, Apache 2, MySQL 4.1, PHP 4.4)

Profile
 
 
Posted: 22 January 2007 10:10 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

Jozef, that’s not a requirement, it’s just a feature I’ve added for people who can’t or don’t want to set up rewriting rules - maybe because of the server configuration, or the software itself (IIS, etc.)  I’ve updated the original post to make that clear.

Might I add that this is also a solution to the garbage-in, garbage-out problem of CI screwing up input data with magic quotes enabled.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 22 January 2007 10:39 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  109
Joined  05-25-2006

Champs, i have tested it again, but it does not work.
I have installed your classes in application/libraries and changed config.php:

$config['query_string_routing'] = true;
$config['enable_query_strings'] = true;
$config['index_page'] = "index.php";


This URL pattern

/index.php/controller?query=foo


returns error:

The URI you submitted has disallowed characters: query=foo

 Signature 

CI 1.5 on WAMP (W2k Pro, Apache 2, MySQL 4.1, PHP 4.4)

Profile
 
 
Posted: 22 January 2007 10:45 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

If you’re using query string routing, the pattern should be:
/index.php?/controller?query=foo

Otherwise, if you don’t want to use query string routing, don’t set that config option.  I’ll update the post again.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 22 January 2007 10:57 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  109
Joined  05-25-2006

I have changed to:
$config[‘query_string_routing’] = false;
or removed it from config.php and
still the error for URL /index.php/controller?query=foo

 Signature 

CI 1.5 on WAMP (W2k Pro, Apache 2, MySQL 4.1, PHP 4.4)

Profile
 
 
Posted: 22 January 2007 11:00 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

When I get some time in my workday, I’ll check it out.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 24 January 2007 07:56 PM   [ Ignore ]   [ # 11 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

The problem (from what I can see) is that the inherited CI code has a special short circuit when there’s only one query string parameter.  I thought I squashed that bug, but I guess not.  Will have a fix soon.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 28 January 2007 04:09 AM   [ Ignore ]   [ # 12 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

... and I’ve posted a fix.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
Posted: 29 January 2007 02:42 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
RankRank
Total Posts:  109
Joined  05-25-2006
champs - 28 January 2007 04:09 AM

... and I’ve posted a fix.

I have tested it again. It works in my project now grin
I would like to see support for $_GET in the next CI release !!!

 Signature 

CI 1.5 on WAMP (W2k Pro, Apache 2, MySQL 4.1, PHP 4.4)

Profile
 
 
Posted: 01 February 2007 11:02 PM   [ Ignore ]   [ # 14 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6712
Joined  03-23-2006

Hey Champs.  This is pretty dense smile  Could you give the the “executive summary” of what you think should be changed?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 01 February 2007 11:42 PM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  187
Joined  06-25-2006

Executive summary: consistency.

Whether you use mod_rewrite or not, the router allows an unlimited number of segments, rather than the very lame controller & method triggers, which don’t work with URL helper functions (my mod works withthem).

Data retrieved from the Input class is predictable.  Whether magic quotes are enabled or not, the data received from the Input class will be the same.  If your data is sane coming in, you don’t have to worry about it again until it’s going out.

 Signature 

Join us in #codeigniter on irc.freenode.net

Profile
 
 
   
1 of 2
1
 
‹‹ Customizing Helpers      paypal paymant ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64450 Total Logged-in Users: 27
Total Topics: 80957 Total Anonymous Users: 0
Total Replies: 435674 Total Guests: 183
Total Posts: 516631    
Members ( View Memberlist )