Samet Kilictas’s Blog

Tag: php

CodeIgniter How to Pagination

by Samet Kilictas on Nov.12, 2008, under General, PHP, Tips

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.

CodeIgniter’s Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.

If you are not familiar with the term “pagination”, it refers to links that allows you to navigate from page to page, like this:

« First < 1 2 3 4 5 > Last »

function shownews()
{
if($this->userlib->logged_in())
//checking for security purposes
{
$this->load->library('pagination');
$per_page = 10;
// How many pages you want to show in each page
$total = $this->db->get('posts', $per_page, $this->uri->segment(3)); 

//Here is the most important part actually.
Basically $total variable determined which
rows you are going to show in the page

$config['base_url'] = base_url().'/index.php/admin/shownews';
$config['total_rows'] = $this->db->count_all('posts'); // Count total rows in the query
$config['per_page'] = $per_page;
$config['num_links'] = 6;
$this->pagination->initialize($config);
$data['posts'] = $total;
$this->load->view('admin_shownews', $data);
} else {
$this->load->view('admin_logineed');
}
}

After getting done with this configuration part of pagination class all you have to do is just initialize it like you are doing it in most of programming languages.

(continue reading…)

VN:F [1.0.6_327]
Rating: 6.5/10 (19 votes cast)
1 Comment :, , , , , , , , more...

A simple password generator

by Samet Kilictas on Sep.10, 2008, under PHP, Programming

You are going to need this for sure : )

function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength &amp; 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength &amp; 2) {
$vowels .= "AEUY";
}
if ($strength &amp; 4) {
$consonants .= '23456789';
}
if ($strength &amp; 8 ) {
$consonants .= '@#$%';
}

$password = '';
$alt = time() % 2;
for ($i = 0; $i &lt; $length; $i++) {
if ($alt == 1) {
$password .= $consonants[(rand() % strlen($consonants))];
$alt = 0;
} else {
$password .= $vowels[(rand() % strlen($vowels))];
$alt = 1;
}
}
return $password;
}

and..
(continue reading…)

VN:F [1.0.6_327]
Rating: 0.0/10 (0 votes cast)
Leave a Comment :, , more...

Coding Guidelines For Developers

by Samet Kilictas on Aug.24, 2008, under General, Research

@author andrej arn
@author sam blume
@version 4.6 updated 2005-11-24

Basically…
we’d like to have a clean and professional, bug-free code.
Most people have different coding styles. And most think that
“the other style” is ugly. We don’t want to force you changing
your style. Here is how we do it and like it:

o) We use capital letters for constants. e.g. define(‘CONSTANT’, 1).
We also use the capital form of TRUE, FALSE and NULL.
This is true for PHP, note that javascript needs lowercase.

o) If a function is described to return bool, expect to get a real bool
(TRUE/FALSE) and not an int (0/1). So please code your functions and
methods that way.

o) Don’t trust the return values from php methods. If they are stated
to return bool, they often return an int (0/1). So don’t directly
return that from your functions, convert to (bool) if necessary.

o) Never ever use echo, print and die and the like inside your methods.
Use return.

o) this applies also for white spaces. if you start your file with anything
(an empty line) before the   considered as output. This makes header() calls impossible (cookie,
session). The same applies for white spaces after the ?> tag. take care!
Even a newline is too much. This is a typical php newbie mistake.

o) Everything should be as os independant as possible. Including windows.

o) Make your code work with PHP version 4.3.0+ and 5.0.5+.
Don’t support php3.

o) Make the php exam. Repeat it from time to time.

http://www.blueshoes.org/en/developer/syntax_exam/

(continue reading…)

VN:F [1.0.6_327]
Rating: 9.3/10 (3 votes cast)
Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...