reset and begin
8/14/2009

fix Cannot redeclare

Cannot redeclare function() (previously declared in...
when using include
when a page is called, a file called a.php is included to check if the username and password of the user are correct. This file includes b.php. However, I also included a.php in the file after including b.php.
who has this problem, change require(...); or include(...); to require_once(...); or include_once(...);.

list in php

he list() function is used to assign values to a list of variables in one operation.

<?php
$my_array = array("Dog","Cat","Horse");

list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>

ex 2

<?php
$my_array = array("Dog","Cat","Horse");

list($a, , $c) = $my_array;
echo "Here I only use the $a and $c variables.";
?>

using to store array

Variable Types in php

PHP supports eight primitive types.

Four scalar types:

  • boolean : expresses truth value, TRUE or FALSE. Any non zero values and non empty string are also counted as TRUE.
  • integer : round numbers (-5, 0, 123, 555, ...)
  • float : floating-point number or 'double' (0.9283838, 23.0, ...)
  • string : "Hello World", 'PHP and MySQL, etc


Two compound types:

  • array
  • object

And finally two special types:

  • resource ( one example is the return value of mysql_connect() function)
  • NULL

In PHP an array can have numeric key, associative key or both. The value of an array can be of any type. To create an array use the array() language construct like this.

<?php
$numbers = array(1, 2, 3, 4, 5, 6);
$age = array("mom" => 45, "pop" => 50, "bro" => 25);
$mixed = array("hello" => "World", 2 => "It's two";

echo "numbers[4] = {$numbers[4]}
";
echo "My mom's age is {$age['mom']}
";
echo "mixed['hello'] = {$mixed['hello']}
";
echo "mixed[2] = {$mixed[2'}";
?>

When working with arrays there is one function I often used. The print_r() function. Given an array this function will print the values in a format that shows keys and elements

<?php
$myarray = array(1, 2, 3, 4, 5);
$myarray[5] = array("Hi", "Hello", "Konnichiwa", "Apa Kabar");

echo '

';
print_r($myarray);
echo '
';
?>

Don't forget to print the preformatting tag

      and 
before and after calling print_r(). If you don't use them then you'll have to view the page source to see a result in correct format.

Type Juggling

In PHP you don't need to explicitly specify a type for variables. A variable's type is determined by the context in which that variable is used. That is to say, if you assign a string value to variable $var, $var becomes a string. If you then assign an integer value to $var, it becomes an integer.

An example of PHP's automatic type conversion is the addition operator '+'. If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float. Otherwise, the operands will be interpreted as integers, and the result will also be an integer. Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.

Example :

<?php
$myvar = "0"; // $myvar is string (ASCII 48)
$myvar += 2; // $myvar is now an integer (2)
$myvar = $foo + 1.3; // $myvar is now a float (3.3)
$myvar = 5 + "10 Piglets"; // $foo is integer (15)
?>

Type Casting

To cast a variable write the name of the desired type in parentheses before the variable which is to be cast.

<?php
$abc = 10; // $abc is an integer
$xyz = (boolean) $abc; // $xyz is a boolean

echo "abc is $abc and xyz is $xyz
";
?>

The casts allowed are:

  • (int), (integer) - cast to integer
  • (bool), (boolean) - cast to boolean
  • (float), (double), (real) - cast to float
  • (string) - cast to string
  • (array) - cast to array
  • (object) - cast to object

Running PHP cron jobs

Scheduled tasks are a fairly common feature in modern web applications. From cleaning out caches every 24 hours to checking subscription periods and even generating reports, more web applications live by the clock than ever before. But how do we schedule the execution of a PHP script on the server side?The answer, for Linux-based servers, is crontab. The crontab utility on UNIX systems allows commands to be executed and predefined intervals. These commands are essentially the same commands as you would run from any local console. For example, you could create a new cron “job” to run a bash script, and set it to run once per day at 12:00 midnight.In terms of PHP, we can then call our PHP scripts via command line using the `php` binary. There are two issues here: first, we need to know where PHP is, and second, we need to know where our scripts are. Say your scripts are in /home/username/example.com, and your PHP binary is in /usr/bin, Your command to run your script could be this:/usr/bin/php /home/username/example.com/myscript.phpNow, we have to configure cron to execute this. If your host has cPanel, you may have a cron job interface which will take this command as an option and allow you to configure visually the times at which it will execute. If you don’t have some kind of web-based interface, you’ll need to go one step further and manually create crontab entries via a command line terminal.Fire up a console window at your server (e.g. in PuTTY) and run “crontab -e”. If you are prompted for an email address, enter an address you can easily manage e.g. a gmail inbox or a catch-all. A command-line text editor such as nano or vi/emacs should appear, and you’re ready to start creating crontab entries.Here’s a sample entry:0 0 * * * /usr/bin/php /home/username/myscript.phpThe first section is the key: this defines the timing. There are five fields, minute, hour, day of month, month and day of week. Each takes a numerical value (typically starting at 0, not 1) or an asterisk to represent “all values”. Ranges are also an option, e.g. 1-5. For example, here we want the 0th minute of the 0th hour of every day of month, every month, on every day of week – in otherwords, midnight every day. This page has a great tutorial on cron scheduling.Once you’ve worked out the cron entry for your intended timing, just add the entry to your crontab file – edited by running `crontab -e` – and save and exit. Crontab will automatically manage the changes and start scheduling your tasks immediately. If your scripts have any output, you will also receive an email with the output. Practise this a little, and within no time you’ll be a PHP task scheduling master
by Akash Mehta

fix Maximum execution time of 30 seconds exceeded

in php.ini
search and config:
" max_execution_time = 30"
become
" max_execution_time = 1000"

fix error upload post big file

upload error in php
in file php.ini search and config:

post_max_size = 100M;
upload_max_filesize = 2000M;

8/12/2009

blogspot-creat border for code


.codeviews {
margin : 15px 35px 15px 15px;
padding : 10px;
clear : both;
list-style-type : none;
background : #f9f9f9;
border-right : 2px solid #cccccc;
border-bottom : 2px solid #cccccc;
border-left : 20px solid #CECECE;
}
using code
tab span with class = codeview

asp.net-Ajax Tutorial for Beginners

asp.net-Ajax Tutorial for Beginners
AJAX1.jpg
Introduction

Hello everyone. This is my first article on The Code Project. I hope you will get some benefit from it. I have been learning Ajax for the last 5 months and now I want to share my knowledge with you. Please provide feedback on any mistakes which I have made in this article. Believe me guys, your harsh words would be received with love and treated with the top most priority.

I have explained Ajax with XML and JSON in part 2, which you can read here

There are many books and articles out there explaining the 5 Ws (Who, What, Where, When, Why) of Ajax, but I will explain to you in my own simple way. So what is Ajax? The term AJAX (Asynchronous JavaScript and XML) has been around for three years created by Jesse James Garrett in 2005. The technologies that make Ajax work, however, have been around for almost a decade. Ajax makes it possible to update a page without a refresh. Using Ajax, we can refresh a particular DOM object without refreshing the full page.
Background of Ajax

In Jesse Garrett’s original article that coined the term, it was AJAX. The “X” in AJAX really stands for XMLHttpRequest though, and not XML. Jesse later conceded that Ajax should be a word and not an acronym and updated his article to reflect his change in heart. So “Ajax” is the correct casing. As its name implies, Ajax relies primarily on two technologies to work: JavaScript and the XMLHttpRequest. Standardization of the browser DOM (Document Object Model) and DHTML also play an important part in Ajax’s success, but for the purposes of our discussion we won't examine these technologies in depth.
How Ajax Works

At the heart of Ajax is the ability to communicate with a Web server asynchronously without taking away the user’s ability to interact with the page. The XMLHttpRequest is what makes this possible. Ajax makes it possible to update a page without a refresh. By Ajax, we can refresh a particular DOM object without refreshing the full page. Let's see now what actually happens when a user submits a request:

AJAX2.JPG

1. Web browser requests for the content of just the part of the page that it needs.
2. Web server analyzes the received request and builds up an XML message which is then sent back to the Web browser.
3. After the Web browser receives the XML message, it parses the message in order to update the content of that part of the page.

AJAX uses JavaScript language through HTTP protocol to send/receive XML messages asynchronously to/from Web server. Asynchronously means that data is not sent in a sequence.
Common Steps that AJAX Application Follows

The figure below describes the structure of HTML pages and a sequence of actions in Ajax Web application:

How Ajax Works

1. The JavaScript function handEvent() will be invoked when an event occurred on the HTML element.
2. In the handEvent() method, an instance of XMLHttpRequest object is created.
3. The XMLHttpRequest object organizes an XML message within about the status of the HTML page, and then sends it to the Web server.
4. After sending the request, the XMLHttpRequest object listens to the message from the Web server.
5. The XMLHttpRequest object parses the message returned from the Web server and updates it into the DOM object.

Let's See How Ajax Works in the Code

Let’s start to put these ideas together in some code examples.
Collapse

form id="form1" runat="server"

div
input type="text" id="lblTime"

br
input type="button" id="btnGetTime" value="Get Time" onclick="GetTime();"

div
form

1. From the above code, our DOM object is (input type="text" id="lblTime") which we have to refresh without refreshing the whole page. This will be done when we press the event of a button, i.e. onclick.
2. In this code, our handEvent() is GetTime() from the above Figure-2 if you take a look at it.

Let's see now how we create an XmlHttpRequest object and make Ajax work for us.

The basic implementation of the XMLHttpRequest in JavaScript looks like this:
Collapse

var xmlHttpRequest;

function GetTime()
{
//create XMLHttpRequest object
xmlHttpRequest = (window.XMLHttpRequest) ?
new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");

//If the browser doesn't support Ajax, exit now
if (xmlHttpRequest == null)
return;

//Initiate the XMLHttpRequest object
xmlHttpRequest.open("GET", "Time.aspx", true);

//Setup the callback function
xmlHttpRequest.onreadystatechange = StateChange;

//Send the Ajax request to the server with the GET data
xmlHttpRequest.send(null);
}
function StateChange()
{
if(xmlHttpRequest.readyState == 4)
{
document.getElementById('lblTime').value = xmlHttpRequest.responseText;
}
}

1.

Now from the above Figure-2 handEvent() i.e. GetTime() creates an XMLHttpRequest object inside it like this:
Collapse

//create XMLHttpRequest object
xmlHttpRequest = (window.XMLHttpRequest) ?
new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");

2.

If the browser does not support Ajax, it will return false.
3.

Next we open our connection to the server with our newly created XMLHttpRequest object. Here the Time.aspx page is the page from which we will get XML message that is stored on the Web server.
Collapse

//Initiate the XMLHttpRequest object
xmlHttpRequest.open("GET", "Time.aspx", true);

4.

You often hear the term “callback” replace the term “postback” when you work with Ajax. That’s because Ajax uses a “callback” function to catch the server’s response when it is done processing your Ajax request. We establish a reference to that callback function like this. Here StateChange is a function where we update or set a new value to our DOM object, i.e "lblTime".
Collapse

//Setup the callback function
xmlHttpRequest.onreadystatechange = StateChange;

Let's have a look at our callback function:
Collapse

function StateChange()
{
if(xmlHttpRequest.readyState == 4)
{
document.getElementById('lblTime').value = xmlHttpRequest.responseText;
}
}

onreadystatechange will fire multiple times during an Ajax request, so we must evaluate the XMLHttpRequest’s “readyState” property to determine when the server response is complete which is 4. Now if readyState is 4, we can update the DOM object with the response message we get from the Web server.
5.

As the request method we are sending is "GET" (remember it is case sensitive), there is no need to send any extra information to the server.
Collapse

//Send the Ajax request to the server with the GET data
xmlHttpRequest.send(null);

In Time.aspx.cs on Page_Load event, write a simple response like this which is our response message:
Collapse

Response.Write( DateTime.Now.Hour + ":" + DateTime.Now.Minute +
":" + DateTime.Now.Second );

That’s it. That’s Ajax. Really.

Key Points to be Remembered in Ajax

There are three key points in creating an Ajax application, which are also applicable to the above Tutorial:

1. Use XMLHttpRequest object to send XML message to the Web server
2. Create a service that runs on Web server to respond to request
3. Parse XMLHttpRequest object, then update to DOM object of the HTML page on client-side

http://www.codeproject.com/KB/ajax/AjaxTutorial.aspx

List

Profiles Information


About me : Nothing is 1 vài thứ - 1985

Places I've Lived : I Hà Nội

Home Page : http://www.shimivn.blogspot.com/

Think : 1:1000000000

Languages spoken : Vietnamese,English.

Mobile : sony C2305

dell : i3-Ram 3GB- HDD 250GB .