Posted on April 14, 2010. Filed under
Frameworks.
No Comments »
Need something lightweight? Something that has a small footprint? Well those are the exact messages EllisLab, Inc. are trying to deliver to web developers. CodeIgniter is a very small, fast and efficient, easy to learn framework that helps rapidly deploy bottom up PHP applications. Similar to PHPCake, its’ goals are to move straight forward to the real development work and cruise pass the routine back-end work such as database configurations, session handling, and permalinks.

MVC Example
C.I. uses a programming model called an MVC (Model-View-Controller). The model provides the data in which the controller processes it and the view displays the data processed by the controller. This model helps keep applications organized, OOP oriented, and separates the developer from the programmer. Though the initial deployment does not have a template engine enabled, it does offer a template parser class through its extensive library.
The framework’s library is what really makes CodeIgniter a real winner. Several classes help start up your application such as a sql/odbc query class, pagination class, session class (handled via cookies), benchmarking class, XML-RPC class and several others that really help launch bottom up applications. With an extensive up to date user guide, it definitely makes learning all the libraries a breeze. If there’s anything too complicated, C.I.’s forums become a really great resource to receive help and collaborate with others. Think of CodeIgniter as the WordPress for Custom PHP applications, its not hard setting up and and its easy to get started; you’re not bound to many rules (unlike other PHP frameworks). There’s a ton of 3rd party plugins and libraries that bring CodeIgniter into the future of rapid web based application development. With its great debugging tools, auto-loading libraries, and online community support, its definitely worth testing future applications on this fantastic framework.
http://codeigniter.com/
http://codeigniter.com/user_guide/ <– Excellent documentation
I just recently started using CodeIgniter for a recently iPhone Web App (http://bowl.mattlo.info) for testing purposes and now going to start using it for my clients. The only thing I’m getting used to is when I’m using AJAX to send info via URI, I have to use a permalink-style link because CodeIgniter does not allow you to use $_GET in PHP. Though you can disable that rule, I’d rather just get used to the permalink structure of passing data. I will write a more extensive C.I. article once I really master the framework. This is an extremely brief overview of CodeIgniter and I strongly encourage you try out the framework yourself!
Posted on April 6, 2010. Filed under
Coding.
No Comments »
Recently I ran into a problem where I needed http://www.domain.com/index.php 301 redirected to http://www.domain.com/ and if you redirect index to ./ you will run into an infinite loop situation. Since root is index.php, 301 redirecting using header() will just call index.php again, and on reload it’ll do the same thing. Using REQUEST_URI in PHP you can determine what the exact URL instead of looking up the absolute path which will always end up with index.php. My solution is below.
if($_SERVER['REQUEST_URI'] == "/index.php") {
header("HTTP/1.1 301 Moved Permanently");
header("location: http://YOUR-DOMAIN-NAME.COM/");
}
Very easy alternative if you don’t have .htaccess (like on Windows Servers).
Posted on November 16, 2009. Filed under
Coding,
Scripts,
Security.
1 Comment »
1) Tracking – In addition with cookies, IP addresses can be useful for tracking individual computers or networks. Take example one of the worlds greatest tracking analysis websites—Google Analytics (aka Urchin). Using IP Based information, Google can track, look up past visits, know what pages you visited, and what pages you came from (using http refer). IPs can give the anonymous visitor a name and collect data on that name.
2) User Interactivity – Display a user online script or even develop an online chatting program based on IP availability. With Session Handling, you could have people interact with each other by classifying IPs and logged in users that match those IP Addresses. Majority of online games are based using IPs. Though Session Handling could also provide user interactivity alone..
3) Ban Hammer – The three most effective way of banning someone off your website is Email, Username, and IP Address. Email and username are only available if users have the option to register their name. IP Addresses can be recorded without the user knowing. The only backdraw to this is if you ban an IP thats networking 10 computers, all 10 computers will be banned. That is the only downside when using IP as a ban hammer (though used commonly across the web).
4) Exceptions – Want to make a private viewing site specific towards a network? IP Exception (along with Cookies) are excellent. Give people cookies, record their IP Address, show them a sneak peak of what you’re working on. Great for showing a specific client how much work has been completed (if your a web developer) or if your just showing a small crowd of people a video and not want to program a login script.
Posted on November 2, 2009. Filed under
Marketing.
No Comments »
Ever wanted to download followers from somebody’s Twitter account in a basic list format? I recently made one that does just that. Its pretty easy to use too (has some jQuery to have a better interface).
Download Twitter Follower PHP Script
Note: This is just a quick version of the script, not really tested in secure environments or anything. Expect the script to break if you don’t type in a real screen name, watch your API call limits, or if you don’t have a valid authentication login.
Instructions
- Download, Extract, Upload to Web Server
- Edit get.php (username and password)
- http://path.to/script
- Type in a valid screen name and you’re good to go
There are limitations to this such as the Twitter API calling limit. You can only follow so many people before the script breaks unless your IP or account is whitelisted. You might think..well okay the API call limit per hour is 150, that means I can search 150 screen names in 1 hour, that’s not bad at all. WRONG. The program can only grab 100 followers per call, so say I wanted to grab an account with 1000 followers, it will take 10 API calls to grab all 1000 followers. If you wanted to grab 10 accounts with 1000 followers…well you can do the math. 15 Accounts per hour with that situation is inefficient. Getting an account whitelisted can help ya overcome that limit.
For a more professional version of this script with more features, contact me and I will give you a quote. It’s good having such a feature on your site, it’ll help you market your business or website better with millions of twitter accounts recorded on your database.
Posted on August 19, 2009. Filed under
Coding.
2 Comments »
For a while I’ve been using PHP’s extension cURL and SimpleXML to obtain API XML info from sites like Twitter and Bizzare Creations. Since the format for RSS feeds and XML are the same, I don’t see why I can’t use the same method so I’ve decided to try it out.
Normally I would make a class and all but for display purposes I’m going to keep it simple. Remember, you need to have cURL and SimpleXML extension enabled in your php.ini
$rss_feed = "http://www.bungie.net/News/NewsRss.ashx"; // halo 3 news eh?
$ch = curl_init($rss_feed);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
$data = curl_exec($ch); // put data from rss url into variable
curl_close($ch);
All thats happening on top is simply going to the URL provided and getting the rss feed source code (aka the info).
// handle the xml data parsing
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
// Do some testing with the data using print_r();
// We gotta see what info we need
print_r($xml);
// it'll show all the data from the RSS feed but we
// only need the news so lets shrink our test
print_r($xml->channel);
// item is an array so we can put a loop to process it
// NOTE: channel and item are the variables used in the source feed
// Other RSS Feeds may not have all this, though it should be standard
foreach($xml->channel->item) {
$item->description; // will show each description for each item
// other options that can be included (by doing tests,
// you can find out what options are available)
// title, link, pubDate, guid, description
$item->link; // would give you the url to the news article
$item->title; // title of the article, obviously
// AGAIN: variables names may be different, use print_r($xml)
// to initially find out your variables
}
Thats it! The Step Process is as simple as 1, 2, and 3.
1) Get info via cURL
2) Parse info via SimpleXML
3) Select what you need by viewing the whole variable, and pick vars out
When the loop was occurring, you notice that I didn’t start the url using $xml. That’s because the [ITEM] tag was already converted into a SimpleXML format (all the variables were) so using $item->description is definitely valid. $xml->channel->item[0]->description will get the same result if you want to see a different perspective in whats going on.
If you want to play around with the data, instead of echoing the variables, just have other variables equal them for organization.
Full working source below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| <?php
$ch = curl_init('http://www.bungie.net/News/NewsRss.ashx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
foreach($xml->channel->item as $item) {
foreach($item as $key=>$details) {
// XML is all the way down to
// the core array, no need
// to do $xml->... or
// $item->...
// the loop did the work for us
echo '<strong>'.ucwords($key).
':</strong> '.$details.'<br />';
}
echo '<br /><br />';
}
?> |