Part of the EllisLab Network
   
 
$_GET[] causing problems with 1.3
Posted: 04 April 2006 08:45 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  61
Joined  03-20-2006

In 1.2 I was accessing some query variables in the URL using the PHP $_GET[] method. I was using this for directing forms, and it worked quite well.

Now in 1.3, the same method works, but throws a PHP Notice:

Error:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: controllers/test.php
Line Number: 67

Line 67:

if($_GET['name']) redirect('test/person/'.$_GET['name']);

Any idea how to access the URL vars properly to avoid this notice? Thanks.

Profile
 
 
Posted: 04 April 2006 08:49 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  547
Joined  03-08-2006

You’ll probably want to use isset() or array_key_exists to see if the name exists in the array first before checking contents or whatever you need it to do… grin

 Signature 

Twitter | Flickr | Last.fm | Del.icio.us

Profile
 
 
Posted: 04 April 2006 09:00 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  37
Joined  03-30-2006

Code Igniter’s Input and Security Class destroys the $_GET array. You can give the $_REQUEST array a try, which is a build of the $_POST, $_GET, and $_COOKIE arrays within one, but not sure how well that will work for you - it’s worth a shot.

On a side note: you are opening yourself up to quite a few security vulnerabilities without a strong validation backend on that page.

 Signature 

Michael Wales, Electronic Information Integration CSA, United States Air Force

Profile
 
 
Posted: 04 April 2006 09:01 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  61
Joined  03-20-2006

I went back through the docs and found

$this->input->post('var')

is exactly what I’m looking for. Thanks.

Profile
 
 
Posted: 04 April 2006 09:03 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  37
Joined  03-30-2006

Does CI convert all of the variables within the $_GET array over to $_POST so they can be used via input->post? I didn’t read that anywhere but if it works - hoorah!

My original suggestion was to use input->post, but after rereading your post you weren’t referring to $_POST data…

Can anyone clarify for me? Thanks.

 Signature 

Michael Wales, Electronic Information Integration CSA, United States Air Force

Profile
 
 
Posted: 04 April 2006 09:08 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  61
Joined  03-20-2006

I’m not sure that it converts them… I had to change my forms to method=post for it to work.

Profile
 
 
Posted: 04 April 2006 09:13 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  37
Joined  03-30-2006

Ah - well I was going to suggest that to begin with but I figured there was a legitimate reason you were using GET, although I can’t think of one myself - when you take all of the security issues into consideration. smile

Glad to see you found a solution. Make sure you tack on that 2nd parameter when you retrieve the data the first time so you can save yourself from an data injection vulnerabilities:

$username = $this->input->post('username', TRUE);

Then just refer to the $username variable (which is a safe version of the user’s submission) from there on out.

 Signature 

Michael Wales, Electronic Information Integration CSA, United States Air Force

Profile
 
 
Posted: 04 April 2006 09:39 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  61
Joined  03-13-2006

It doesn’t.  at least i last time i checked i didnt find any code that did anything similar.

Profile
 
 
Posted: 04 April 2006 10:22 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  85
Joined  04-01-2006
Evic - 04 April 2006 09:00 AM

On a side note: you are opening yourself up to quite a few security vulnerabilities without a strong validation backend on that page.

I don’t see how, it’s merely sending header details to the browser to redirect to a page. It’s not explosing any details.

CI doesn’t accept $_GET because it uses its segment approach, your best bet it is to use post, or parse_str the segment which the $_GET details are in, although it may need a little messing around with.

Profile
 
 
   
 
 
‹‹ Cookie woes      Autoload script scope ››
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 819, on March 11, 2010 11:15 AM
Total Registered Members: 120493 Total Logged-in Users: 40
Total Topics: 126564 Total Anonymous Users: 2
Total Replies: 665425 Total Guests: 333
Total Posts: 791989    
Members ( View Memberlist )