Archive

Author Archive

PopUp Boxes

July 31, 2010 1 comment

Basis

1.Alert Box
-The syntax for an alert box is: alert(“text”);
-The user will need to click “OK” to proceed.
-It is used when you want to make sure information comes through to the user.
Ex
alert(“Please enter your name”);
Examples of alert box could be warnings of any kind.

2.Confirm Box
-The syntax for a confirm box is: confirm(“text”);
-The user needs to click either “OK” or “Cancel” to proceed.
-It is used when you want the user to verify or accept something.
Ex
if (confirm(“Submit”)){
alert(“Ok”)
}
else{
alert (“Cancel”)
};
If the user clicks “OK”, the box returns the value true.
If the user clicks “Cancel”, the box returns the value false.

3.Prompt Box
-The prompt box syntax is: prompt(“text”,”defaultvalue”);
-The user must click either “OK” or “Cancel” to proceed after entering the text.
-The user should input a value before entering the page.
Ex
username=prompt(“Please enter your name”,”Enter your name here”);
The value stored in a variable called username.

Categories: JavaScript

Sessions in PHP

July 29, 2010 Leave a comment

Basis

Sessions are used to store information which can be used through-out the application for the entire time the user is logged in or running the application. Each time a user visits your website, you can create a session for that user to store information pertaining to that user.

In web applications, all the stored variables and objects are not globally available throughout all pages, so to tackle this problem sessions are utilized.

1.Starting Sessions-In PHP, information is stored in session variables. Before you can store any information in session variables, you must first start up the session using the session_start() function.

Ex

<?php
session_start();
?>

<html>
<body>

</body>
</html>

Outline

When you start a session a unique session id (PHPSESSID) for each visitor/user is created. You can access the session id using the PHP predefined constant PHPSESSID.

The code above starts a session for the user on the server, and assign a session id for that user’s session.

2.Storing information in a session-To store information is a session variable, you must use the predefined session variable $_SESSION.

Ex

<?php
session_start();

$_SESSION[“username”] = “gopal”;
$_SESSION[“password”] = “gopi123”;
?>

Outline

Here in this example we have store user’s name and their password in a session.

3.Retrieving stored session information-you can access the stored session information on any page.

Ex

<?php
session_start();

echo $_SESSION[“username”];
echo “<br />”;
echo $_SESSION[“password”];
?>

Output

gopal
gopi123

4.Destroying/deleting session information-Remember sessions are destroyed automatically after user leaves website or closes the browser, but if you wish to clear a session variable , you can simple use the unset() function to clean the session variable.

Ex

<?php
session_start();

unset($_SESSION[“username”]);

unset($_SESSION[“password”]);
?>

To completely destroy all session variables in one go, you can use the session_destroy() function.

Ex

<?php
session_destroy();
?>

Categories: PHP

Retrieving Cookie

July 25, 2010 Leave a comment

Basis

If your cookie hasn’t expired yet, let’s retrieve it from the user’s PC using the aptly named $_COOKIE associative array. The name of your stored cookie is the key and will let you retrieve your stored cookie value!

Ex

<?php
if(isset($_COOKIE[‘lastVisit’]))
$visit = $_COOKIE[‘lastVisit’];

echo “Your last visit was – “. $visit;
?>

Outline

Here we have used isset function to be sure that our “lastVisit” cookie still exists on the user’s PC, if it does, then the user’s last visit is displayed.

Categories: PHP

Creating PHP Cookies

July 25, 2010 Leave a comment

Basis

When you create a cookie, using the function setcookie, you must specify three arguments. These arguments are setcookie(name, value, expiration):

1. name: The name of your cookie. You will use this name to later retrieve your cookie.
2. value: The value that is stored in your cookie. Common values are username(string) and last visit(date).
3. expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted.

Ex

<?php
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie(‘lastVisit’, date(“G:i – m/d/y”), $inTwoMonths);
?>

Outline

In this example we will be creating a cookie that stores the user’s last visit to measure how often people return to visit our webpage. We want to ignore people that take longer than two months to return to the site, so we will set the cookie’s expiration date to two months in the future!

Categories: PHP

PHP Functions – Parameters

July 24, 2010 Leave a comment

Basis

Another useful thing about functions is that you can send them information that the function can then use.

Ex

<?php
function greeting($name){
echo “Hello there “. $name . “!<br />”;
}
greeting(“arjun”);
greeting(“gopal”);
greeting(“sunil);
greeting(“rahul”);
?>

Output
Hello there arjun!
Hello there gopal!
Hello there sunil!
Hello there rahul!

Outline

However, if we were to use parameters, then we would be able to add some extra functionality! A parameter appears with the parentheses “( )” and looks just like a normal PHP variable.
Here we have created a function which creates a custom greeting based off of a person’s name.Our parameter will be the person’s name and our function will concatenate this name onto a greeting string.
When we use our greeting function we have to send it a string containing someone’s name, otherwise it will break.

Categories: PHP

PHP – Functions

July 24, 2010 Leave a comment

Basis

A function is just a name we give to a block of code that can be executed whenever we need it.

Ex

<?php
function myfunction(){
echo “i am in function. <br />”;
}
echo “Hello world. <br />”;
myfunction();
myfunction();
?>

Output

Hello world.
i am in function.
i am in function.

Outline

– Always start your function with the keyword function.
– Remember that your function’s code must be between the “{” and the “}”.
– When you are using your function, be sure you spell the function name correctly.

Categories: PHP

Validating Form Input: Numbers

July 23, 2010 Leave a comment

Basis

You want to make sure a number is entered in a form input box.

Ex

<?php
if (! ctype_digit($_POST[‘age’])) {
print ‘Your age must be a number bigger than or equal to zero.’;
}
?>
Outline

In this example age is checked to know whether the value entered by the user is a number or not.ctype_digit() is used to validate the form input.

Categories: PHP

Copy to Clipboard in javascript using zeroclipboard

July 22, 2010 Leave a comment

zeroclipboard
After hrs of debugging able to figure out how to copy to clipboard. The solution provided by zeroclipboard seems to be working, but sometime bit time consuming to do it correctly.


ZeroClipboard.setMoviePath("http://localhost/js/ZeroClipboard.swf');
var clipArr = new ZeroClipboard.Client();
clipArr.setText("Your string interested to copy") ;
clipArr.setHandCursor( true );
clipArr.glue( 'copy-img' );

HTML snippet
<img src=”clickme.png” alt=”” />

Categories: Uncategorized Tags: ,

what is views in Codeigniter

July 18, 2010 Leave a comment

Basis

views are resposnsible for showing the final out as HTML page.Views are loaded in controller to work on.we can have multiple view files like header,footer,index etc.Below is a simple example of creating a view file.after creating save this in your application/views/ folder.

Ex

<html>
<head>
<title>creating view file</title>
</head>
<body>
<h1>It is my view file</h1>
</body>
</html>
//loading view file
<?php
class User extends Controller {
function index()
{
$this->load->view(‘user_view’);
}
}
?>
Outline
once the view file is done we should call like this under our controller.Now we can access the page in this path- example.com/index.php/user/

What is Models in codeigniter

July 18, 2010 Leave a comment

Basis

Models are optionally stored, if you want you can ignore it also.These are designed to work with  database query like insert,update,create,delete and database information.Suppose you want to insert your form data in your database.Just create a model look like below in your model folder.

Ex

class Entry extends Model {
var $name   = ”;
var $password = ”;
var $email    = ”;
function Entry()
{
parent::Model();
}
function insert_data()
{
$this->title   = $_POST[‘name’];
$this->content = $_POST[‘password’];
$this->content = $_POST[’email’];
$this->db->insert(‘user’, $this);
}
}
Outline

Here entry is the name of your class. Class names must start with  capital letter with the rest of the name lowercase. Make sure your class extends the base Model class.
The file name will be a lower case following the file name.Then we have defined a function to insert data.$_POST is used to get retrieve the form data.
Once the model is ready we should load it in controller to work properly.
ex

class user extends Controller {
function blog()
{
$this->load->model(‘entry’);
$data[‘query’] = $this->entry->insert_data();
}
}