Colleen78 Posted June 25, 2008 Share Posted June 25, 2008 Hello, The creator of a modification I am using for my SMF 1.1.5 board seems to have stopped offering support so I'd like to fix this issue myself. The modification takes Amazon links in my forum and adds my associate ID. Here's a link to the modification if it helps, http://custom.simplemachines.org/mods/index.php?mod=893 The error I am getting in the error log is this: 8: Undefined index: host File: /home2/mydomain/public_html/Sources/Subs.php Line: 2390 This is that line: if (preg_match('/(.*)amazon\.(com|co.uk|de|fr|co.jp|ca)+/i', $parsed['host'])) { Here is the rest of the code from around and including that line: // CYCLE THROUGH EACH LINK foreach($links as $link) { $parsed = parse_url($link); // MATCH ANY AMAZON LINKS AND CREATE REPLACEMENTS if (preg_match('/(.*)amazon\.(com|co.uk|de|fr|co.jp|ca)+/i', $parsed['host'])) { $parsed['host'] = str_replace('www.','',$parsed['host']); $parsed['host'] = str_replace('amazon.','',$parsed['host']); // IF THE DOMAIN EXTENSION IS VALID if(isset($temp[$parsed['host']])) { $search[] = '<a href="'. $link. '"' ; $replace[] = '<a href="'. str_replace($parsed['host'], $modSettings['amazonlinksassociatestore'], $link) . ((strpos($link,'?') === FALSE) ? '?' : '&') . 'tag='. $modSettings['amazonlinksassociateid'].'"' ; } } // TIDY UP unset($parsed); } No other parts of the modification mention "$parsed" so I believe the error is limited to these few lines and am guessing it's not coded properly. If anyone has any ideas how to fix this, please let me know. Thanks! Quote Link to comment Share on other sites More sharing options...
effigy Posted June 25, 2008 Share Posted June 25, 2008 Are the URLs in $links valid? parse_url is not finding a host it appears. You can examine this with print_r($parsed); Quote Link to comment Share on other sites More sharing options...
Colleen78 Posted June 25, 2008 Author Share Posted June 25, 2008 I am not sure what you mean, but I did notice this is happening when someone views a page which contains a link that is not an amazon link, if they view a page with an amazon link in the post, no errors, and it works fines, but if I view a post with a link to anything else I get these errors. I think it needs to be coded in what to do if it's a normal link and not an amazon link. Quote Link to comment Share on other sites More sharing options...
effigy Posted June 25, 2008 Share Posted June 25, 2008 Perhaps: if (array_key_exists('host', $parsed) && preg_match('/amazon\.(?:com|co\.(?:uk|jp)|de|fr|ca)/i', $parsed['host'])) { Quote Link to comment Share on other sites More sharing options...
Colleen78 Posted June 25, 2008 Author Share Posted June 25, 2008 Perhaps: if (array_key_exists('host', $parsed) && preg_match('/amazon\.(?:com|co\.(?:uk|jp)|de|fr|ca)/i', $parsed['host'])) { Wow, that did the trick, the errors are gone and everything's still working. Thanks so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.