open a url feed in codeigniter
What's the best way to open a URL feed in codeigniter? I'm assuming I can't put the URL in a file upload input, so should I use a normal text input and then validate that the URL is not malicious? If so, what validation tests should I perform on the user inputted string? Would checking the file extension be enough or can thi开发者_运维技巧s easily be manipulated?
- Use a
<input type="text" />
to let users submit URLs - Check that it is a valid URL using regular expressions (and ignore the extension)
- e.g.
preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
- e.g.
- Consider validating the feed with a feed validator (note that many legit feeds may not be "valid")
- e.g. http://feedvalidator.org/about.html#where
- e.g. http://www.rss-specifications.com/feed-validators.htm
- Try accessing and parsing it
- http://codeigniter.com/wiki/RSSParser/
- http://codeigniter.com/wiki/RSSParser-PhilMod/
- http://www.haughin.com/code/simplepie/
精彩评论