[PHP] Undefined index error
So sometimes I end up with issues that are so simple I should be able to fix it but for some reason I end up asking a stupid question to the list... So... Here goes :) Here is the error: Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php on line 19 and here is Line 19: $data = explode(/, $_SERVER['REQUEST_URI']); When you first hit the site you to go something like: purl.mysupersite.com/YourNameHere If you went to: purl.mysupersite.com/YourNameHere/ (Notice the trailing /) there would be no error... Now I know it's just a undefined index error and I can safely ignore it since it works just fine. All I have to do is turn off the error reporting and it's gone... But I want to write good code... Any Suggestions? -- Jason Pruim japr...@raoset.com 616.399.2355
Re: [PHP] Undefined index error
Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php on line 19 and here is Line 19: $data = explode(/, $_SERVER['REQUEST_URI']); Hi, Are you sure it's an array? Use print_r() or var_dump() on $_SERVER['REQUEST_URI'] on the preceding line. Just for testing, you could do this too: $_SERVER['REQUEST_URI'] = 'It/Works'; ...on the preceding line. -- Richard Heyes HTML5 Graphing for Firefox, Chrome, Opera and Safari: http://www.rgraph.org (Updated January 17th) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
On Jan 19, 2009, at 2:32 PM, Richard Heyes wrote: Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php on line 19 and here is Line 19: $data = explode(/, $_SERVER['REQUEST_URI']); Hi, Are you sure it's an array? Use print_r() or var_dump() on $_SERVER['REQUEST_URI'] on the preceding line. Just for testing, you could do this too: $_SERVER['REQUEST_URI'] = 'It/Works'; ...on the preceding line. actually at that point it's not an array... it's just loading purl.mysupersite.com/test so REQUEST_URI just contains test I just want to squash that error until they go to a page in the site :) I'm thinking I just need to think this one through a little bit and I'm sure the solution ill come to me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
On Mon, Jan 19, 2009 at 14:32, Richard Heyes rich...@php.net wrote: Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php on line 19 and here is Line 19: $data = explode(/, $_SERVER['REQUEST_URI']); When I view that file, on line 19, I see: echo HTML Are you sure it's an array? Use print_r() or var_dump() on $_SERVER['REQUEST_URI'] on the preceding line. Just for testing, you could do this too: $_SERVER['REQUEST_URI'] = 'It/Works'; ...on the preceding line. Well, that wouldn't address the issue of the code he gave on the line reported, but I know what you mean, Richy. He's turning $_SERVER['REQUEST_URI'] into an array with explode() if it contains a forward-slash (/). What would be better in that case would be: ?php $data = isset($_SERVER['REQUEST_URI']) strlen($_SERVER['REQUEST_URI']) 0 ? explode('/',$_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']; if(is_array($data)) { // Handle as appropriate. } ? However, that's not the best option as: 1.) REQUEST_URI may not (though it should) have *any* forward slashes in the URI passed to PHP by the HTTP server. 2.) It leaves too much other stuff to be done. Instead, check out: ?php $data = basename($_SERVER['REQUEST_URI']); echo $data; // In case you're not yet aware of what you'll receive from the use of basename() ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Unadvertised dedicated server deals, too low to print - email me to find out! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
There is no reference to index '2' in that line 19. What is the next line? Something which expects at least 3 elements in the URI, perhaps?... [Hint, hint] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
On Jan 19, 2009, at 3:28 PM, Daniel Brown wrote: On Mon, Jan 19, 2009 at 14:32, Richard Heyes rich...@php.net wrote: Notice: Undefined index: 2 in /home/raosetc/public_html/purl/p.php on line 19 and here is Line 19: $data = explode(/, $_SERVER['REQUEST_URI']); When I view that file, on line 19, I see: echo HTML Only when you log into certain accounts and view the file after I had made changes :P Are you sure it's an array? Use print_r() or var_dump() on $_SERVER['REQUEST_URI'] on the preceding line. Just for testing, you could do this too: $_SERVER['REQUEST_URI'] = 'It/Works'; ...on the preceding line. Well, that wouldn't address the issue of the code he gave on the line reported, but I know what you mean, Richy. He's turning $_SERVER['REQUEST_URI'] into an array with explode() if it contains a forward-slash (/). What would be better in that case would be: ?php $data = isset($_SERVER['REQUEST_URI']) strlen($_SERVER['REQUEST_URI']) 0 ? explode('/',$_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']; if(is_array($data)) { // Handle as appropriate. } ? However, that's not the best option as: 1.) REQUEST_URI may not (though it should) have *any* forward slashes in the URI passed to PHP by the HTTP server. 2.) It leaves too much other stuff to be done. Instead, check out: ?php $data = basename($_SERVER['REQUEST_URI']); echo $data; // In case you're not yet aware of what you'll receive from the use of basename() ? I'm not positive that does exactly what I want... What I'm really going for is given this URL: purl.mysupersite.com/test/mail test refers to a record in the database. mail refers to a file on the server which is included when mail is present. Otherwise the main page is used. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
On Mon, Jan 19, 2009 at 15:39, Jason Pruim japr...@raoset.com wrote: Only when you log into certain accounts and view the file after I had made changes :P I figured you had already changed it, but when you're root, you don't have to log in to other accounts. ;-P What I'm really going for is given this URL: purl.mysupersite.com/test/mail test refers to a record in the database. mail refers to a file on the server which is included when mail is present. Otherwise the main page is used. So then you'll use mod_rewrite, since Apache needs to tell PHP how to parse it. Otherwise, Apache is going to be looking for /test/mail. #.htaccess: # Options -MultiViews RewriteEngine On # ## Redirect to remove trailing slashes on extensionless URL requests # If requested URL ending with slash does not resolve to an existing directory RewriteCond %{REQUEST_FILENAME} !-d # externally redirect to remove trailing slash. RewriteRule ^(.+)/$ /index.php?s=$1 [QSA,L] # ## Externally redirect clients directly requesting .php page URIs to extensionless URIs # If client request header contains php file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.]+\.php\ HTTP # externally redirect to extensionless URI. RewriteRule ^([^.]+)\.php$ /index.php?s=$1 [QSA,R=301,L] # ## Internally rewrite extensionless file requests to .php files ## # If the requested URI does not contain a period in the final path-part RewriteCond %{REQUEST_URI} !(\.[^./]+)$ # and if it does not exist as a directory RewriteCond %{REQUEST_FILENAME} !-d # and if it does not exist as a file RewriteCond %{REQUEST_FILENAME} !-f # then add .php to get the actual filename. RewriteRule (.+) /index.php?s=$1 [QSA,L] # End .htaccess You can figure out the rest yourself. ;-P -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Unadvertised dedicated server deals, too low to print - email me to find out! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
On 6/10/07, Christian Cantrell [EMAIL PROTECTED] wrote: I'm getting this error in my Apache log file, and I can't figure out why: Undefined index: password in /path/to/file.php on line 82 Some searching on Google turned up a bunch of questions, but no answers. Any idea what this warning message is referring to? Thanks, Christian Yes, you're probably trying to get a value from an array by using a key that isn't in the array. Something like this: ?php $array = array( user= test, foo=bar); $value = $array['password']; // Key password doesn't exist! ? Check the line number and print out the array with var_dump/print_r to see what's in the array.. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
Ah, you're right. Thanks, Tijnema. I'm just getting my feet wet with PHP, and you guys are a great help! Christian On 6/10/07, Tijnema [EMAIL PROTECTED] wrote: On 6/10/07, Christian Cantrell [EMAIL PROTECTED] wrote: I'm getting this error in my Apache log file, and I can't figure out why: Undefined index: password in /path/to/file.php on line 82 Some searching on Google turned up a bunch of questions, but no answers. Any idea what this warning message is referring to? Thanks, Christian Yes, you're probably trying to get a value from an array by using a key that isn't in the array. Something like this: ?php $array = array( user= test, foo=bar); $value = $array['password']; // Key password doesn't exist! ? Check the line number and print out the array with var_dump/print_r to see what's in the array.. Tijnema
Re: [PHP] Undefined index error
On Sat, June 9, 2007 11:53 pm, Christian Cantrell wrote: I'm getting this error in my Apache log file, and I can't figure out why: Undefined index: password in /path/to/file.php on line 82 Some searching on Google turned up a bunch of questions, but no answers. Any idea what this warning message is referring to? If you use something like: $_POST['password'] $_COOKIE['password'] // this is a REALLY Bad Idea $_GET['password'] //bad idea $_SESSION['password'] . . . but you don't actually *HAVE* a 'password' in the array, then you will get that error message. Your assumption that you have some kind of password is invalid. Check first: if (isset($whatever['password'])){ //rest of your code in here. } -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Undefined index error
I'm getting this error in my Apache log file, and I can't figure out why: Undefined index: password in /path/to/file.php on line 82 Some searching on Google turned up a bunch of questions, but no answers. Any idea what this warning message is referring to? Thanks, Christian
Re: [PHP] Undefined index error
On Sun, 2007-06-10 at 00:53 -0400, Christian Cantrell wrote: I'm getting this error in my Apache log file, and I can't figure out why: Undefined index: password in /path/to/file.php on line 82 Please post the code on that line of the file indicated. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Undefined index error
I'm using the superglobal $_POST array to access URL parameters passed to my page. I was getting undefined constant errors in my error_log file, and found that I needed to quote the variables in the array. $_POST['SortBy'] etc. Now, it appears that I've just traded the undefined constant errors for undefined index warnings. Everytime a page hits a page with url parameters, it triggers a warning in the error_log file. What's triggering these undefined index errors? I suppose I could lower the logging level in php.ini, but I'd rather code properly than to hide the problem. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Undefined index error
If you try to access a form variable that hasn't been set, you get an undefined index. Try checking with something like if(isset($_POST['SortBy'])) { // do something with 'SortBy' } In any case, you'll get the undefined index warning anytime you try to read an array index that hasn't been set. ..michael.. On Mon, 2002-08-19 at 14:49, Shu Chow wrote: I'm using the superglobal $_POST array to access URL parameters passed to my page. I was getting undefined constant errors in my error_log file, and found that I needed to quote the variables in the array. $_POST['SortBy'] etc. Now, it appears that I've just traded the undefined constant errors for undefined index warnings. Everytime a page hits a page with url parameters, it triggers a warning in the error_log file. What's triggering these undefined index errors? I suppose I could lower the logging level in php.ini, but I'd rather code properly than to hide the problem. Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php