debug PHP code

The trouble is when you are working in a client-server architecture model, because from where you send the request (client) can not access the code hosted on the server.

FirePHP is a Mozilla Firefox complement that merges with Firebug and allows you to watch the outputs sent from PHP code in the console, so, you can watch the variables values or create a log about that is happened in your scripts without use the upset “echo” that interferes with you HTML.

The way FirePHP works is very easy, all the information that you want to view at run time is coded in JSON and sent in the headers of the response. When these headers arrives to the navigator, FirePHP detect it and to render the information in the Firebug console.

 

MySQL Workbench is a visual database design tool that is developed by MySQL. It is Free, Open Source under GPL and easy to use for design and make professional databases. You can download MySQL Workbench in the official downloads section.

 

via http://yensdesign.com/2008/10/how-to-debug-php-code/#more-5

Faster and smarter debugging of PHP scripts

Traditionally, in compiled languages, certain part of code validation (type checking, checking for non-initialized variables) are usually taken by compiler, but besides compiler there are also external tools used to conduct this task (for example checkstyle for Java). This article deals with use of one of those tools (Codenizer) during development of PHP applications.

php create json from mySQL

JSON or Javascript Object Notation is a lightweight text-based open standard designed for human-readable data structures and associative arrays, called objects. it is language-independent, with parsers available for many languages.

The official Internet media type for JSON is application/json. The JSON filename extension is .json. The JSON format is often used for serializing and transmitting structured data over a network connection.

it is used primarily to transmit data between a server and web application.

<?php
mysql_connect("localhost","root","your_db_pass");
mysql_select_db("blog");
$sql=mysql_query("select * from entries");
while($row=mysql_fetch_assoc($sql)){
$output[]=$row;
}
print(json_encode($output));
mysql_close();
?>
running it will be produce a json file, just copy-paste from the page to notepad, then save notepad with extension .json.

openID database

Google OpenID authentication in PHP

Sample database design for table name contact.

This table contains  id (primary key),tutorial and link.

CREATE TABLE IF NOT EXISTS `google_login` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(500) NOT NULL,
  `email` varchar(500) NOT NULL,
  `inserted_on` datetime NOT NULL,
  PRIMARY KEY (`id`)
)

dbConnect.inc.php

Contains database connectivity code

$mysql_db_hostname = "Host name";
$mysql_db_user = "UserName";
$mysql_db_password = "Password";
$mysql_db_database = "Database Name";

$con = mysql_connect($mysql_db_hostname, $mysql_db_user,
       $mysql_db_password or die("Could not connect database");
//Create a new connection
mysql_select_db($mysql_db_database, $con) or
                 die("Could not select database");
// select database

Oauth Login for Linkedin, Facebook, Google and Microsoft

OAuth Login is very quick and powerful, sure this helps you to increase your web project registrations. It’s definitely a must have login system for every PHP based web projects. Hardly it will take 10 mins for installation.

OAuth and OpenID: The differences and the future

OpenID

16257v5 max 250x2501 Facebook Connect, OAuth and OpenID: The differences and the futureOpenID is an old standard. In fact, it hasn’t even been updated since 2007. In its path, however, it has picked up some great sites. For that matter, even Facebook allows you to sign in and use its site via OpenID and users can link their Gmail accounts to the site in the same manner.

The purpose behind OpenID can best be described as an introduction to a stranger. OpenID serves as the third party that can verify who you are. So, when you go to sign in to a new site, the site asks the OpenID server “is this John” and the OpenID server replies that yes, it is John.

The problem with OpenID, according to Dave Recordon, is that v2 of the standard was incredibly difficult to implement:

I’ve heard story after story from developers implementing OpenID 2.0 who don’t understand why it is so complex and inevitably forgot to do something.

So, combine that complexity with the fact that OpenID hasn’t been updated in 3 years and you have a bit of a recipe for disaster. There’s also the problem that it requires more than one handshake (introduction) in order to get data stored on a server. In fact, OpenID cannot, at this point, acquire that information on its own. It has to send a second request for OAuth to handle the information transfer.

There is hope on the horizon, however. Rumors are swirling that OpenID is working on a new standard called OpenID Connect that will be built on top of OAuth. This would allow a single handshake for both identification and data transfer. We’ll do another post about that, later, as more developments happen.

OAuth

300px Oauth logo.svg 1 299x300 Facebook Connect, OAuth and OpenID: The differences and the futureIn a few wordsOAuth is “a simple way to publish and interact with protected data. It’s also a safer and more secure way for people to give you access.” Twitter has implemented it, with the@anywhere platform, as have a number of other sites around the Internet. Version 2 of OAuth, released in May of 2010, is a complete revision of the platform that is purposely not backward-compatible with previous iterations.

OAuth differs from OpenID in that it cannot request identification (at least in its present form). What it can do is allow a 3rd party to have access to your data without the need for you to show your password to that 3rd party site. There is a revision to OAuth that has been proposed, allowing OAuth to acquire identity as well, but it is far from finalized.

That 1.0 version of OAuth had issues of its own. In fact, it spawned the discussion about WRAP, yet another manner of doing the same thing. While the WRAP discussions have gone to the wayside, you can rest assured that the involved parties are watching the current circumstances quite closely.

SUMMARY

OpenID allows a site to make sure that its user owns some personal URL (of a site, blog, profile). This fact is sufficient to use this unique URL to recognize the user next time he logs into the site. That’s it. Everything else — registering accounts, obtaining emails and other data, permitting any activity on the site — is up to the site itself. In other words, OpenID is a pure authentication mechanism: you know who’s come upon your site and you can do with this knowledge whatever you like.

OAuth allows a program (on the web or local) to obtain from a user certain rights to use a particular API. The rights are denoted with a token whose nature is not defined: it can be the same for different users or the same user can be granted different tokens at different times. The only thing guaranteed is that upon presenting the token to the service the program will be able to perform certain actions on it. In other words, OAuth is a pureauthorization mechanism: you have certain rights but you can’t infer their owner’s identity.

Here’s an analogy. OpenID is your driver’s license: it says who you are but it doesn’t imply you’re going to drive a car whenever you’re asked of your ID. OAuth is you car’s key: a valet can drive your car with them but he doesn’t need to know your name to do it.

mysql_fetch_assoc(data)

This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.

 After the data is retrieved, this function moves to the next row in the recordset. Each subsequent call to mysql_fetch_assoc() returns the next row in the recordset.

mysql_fetch_assoc() 和用 mysql_fetch_array() 加上第二个可选参数 MYSQL_ASSOC 完全相同。

strtotime() – Parse English textual datetimes into Unix timestamps:
$date = '25/05/2010';
$date = str_replace('/', '-', $date);
echo date('Y-m-d', strtotime($date));

result:
2010-05-25

  • Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the Americanm/d/y is assumed; whereas if the separator is a dash () or a dot (.), then the European d-m-y format is assumed.
  • To avoid potential ambiguity, it’s best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
  •  If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

jquery.lazyload动态延迟加载页面图片

 

php插入和显示数据库中的图片(处理二进制数据)

将所要显示的图片存在特定的目录下,在数据库中保存相应的图片的名称,然后在PHP中查询数据库获得文件路径并在HTML文件中引用。如果我们想动态显示图片,上述方法就不能满足需要了。因此必须把图片存入数据库,然后通过编程动态地显示我们需要的图片。

在实际操作中,可以利用PHP将图片插入到数据库中(图片是以二进制格式存储),随后可以使用PHP将图片数据读出来并显示在网页上。

使用HTML表单可以将客户端的图片文件作为请求传递给服务端,PHP可以读取请求中的上载文件数据,并将数据保存在数据库中。

<?php
//由于上传过来的图片被保存在一个临时文件中,所以我们仅需要读取该文件就可以获取传过来的图片
$fp = fopen($_FILES["myFile"]["tmp_name"],"rb");
$buf = addslashes(fread($fp,$_FILES["myFile"]["size"]));  
//创建一个PDO对象
$dbh = new PDO("mysql:host=localhost;port=3306;dbname=myDatabase", "root", "verysecret");
//执行插入操作并将结果保存在一个变量中
$result = $dbh->query("INSERT INTO employees (firstName,lastName,EmpType,age,picture) VALUES 
('myFirst','myLast','myEmpType',50,'$buf')");
//获取影响的行数
if ($result->rowCount() >0) {
    echo("数据已插入。");
} else {
    echo("不能执行插入操作。");
}
//显式的关闭PDO连接
$dbh = NULL;
?>
显示数据库中的图片数据
<?php
//创建一个PDO对象
$dbh = new PDO("mysql:host=localhost;port=3306; dbname=myDatabase", "root", "verysecret");
//设置字符编码
$dbh->exec("SET CHARACTER SET gb2312");
//执行查询并将结果保存在一个变量中
$result = $dbh->query("SELECT * FROM employees WHERE firstName = 'myFirst'");
//获取第一行数据
$row = $result->fetch();
//写出数据记录,首先查看是否存在记录
if(!empty($row)){
header("Content-type: image/JPEG",true);
echo($row["picture"]);
}
//显式的关闭PDO连接
$dbh = NULL;
?>

file uploading is corrupted [error]

1. Data URIs represent the data of the image. put all the data URIs the user drags into the box into an array, and post it to a PHP file. This PHP file will process the URIs and upload them to the server.

$randomName = substr_replace(sha1(microtime(true)), ”, 12).’.’.$mime;
if(file_put_contents($uploaddir.$randomName, $decodedData)) {
echo $randomName.”:uploaded successfully”;
}
else {
// Show an error message should something go wrong.
echo “Something went wrong. Check that the file isn’t corrupted”;
}

reason: the folder which holds the uploaded file, has no permission to be written by any user.

resolution: chmod a+w uploadfolder/

2. “I know how to submit data into a mySQL table through a form. Now I want to upload the image file to the remote directory (say, ‘images/’) but at the same time save the file-name in the table. ”

Often you want a user to be able to upload a photo, but you don’t want to bog down your database space by saving all the images directly into the database. You instead save the image to your server, but keep a record in the database of what file was saved so you can easily reference the image when needed.

First let’s create a database:

CREATE TABLE employees (name VARCHAR(30), email VARCHAR(30), phone VARCHAR(30), photo VARCHAR(30)) 

Creating a Form:

This is simply an HTML form that you would use to collect information to be added to the database.

<form enctype="multipart/form-data" action="add.php" method="POST"> 
 Name: <input type="text" name="name"><br> 
 E-mail: <input type="text" name = "email"><br> 
 Phone: <input type="text" name = "phone"><br> 
 Photo: <input type="file" name="photo"><br> 
 <input type="submit" value="Add"> 
 </form>

Processing the Data: add.php

<?php 
 //This is the directory where images will be saved 
 $target = "images/"; 
 $target = $target . basename( $_FILES['photo']['name']); 

 //This gets all the other information from the form 
 $name=$_POST['name']; 
 $email=$_POST['email']; 
 $phone=$_POST['phone']; 
 $pic=($_FILES['photo']['name']); 

 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; 
 mysql_select_db("Database_Name") or die(mysql_error()) ; 

 //Writes the information to the database 
 mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ; 

 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
 {  
 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
 } 
 else {  
 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 
 ?> 
  • only allowing photo uploads, you might consider limiting the allowed file types to jpg, gif and png.
  •  check if the file already exists: not overwrite
  • simply rename each file with a unique ID

Uniqid (prefix, more_entropy)

  • prefix: what will be appended to the beginning of each ID.
  • more_entropy. If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.
<?php

//creates a unique id with the ‘about’ prefix

$a = uniqid(about); echo $a;   echo “<br>”;

//creates a longer unique id with the ‘about’ prefix

$b = uniqid (about, true); Echo $b; echo “<br>”;

//creates a unique ID with a random number as a prefix – more secure than a static prefix

$c = uniqid (rand (),true); echo $c; echo “<br>”;

//this md5 encrypts the username from above, so its ready to be stored in your database

$md5c = md5($c); echo $md5c; ?>

crypt () In Action

<?php
$password = crypt('mypassword'); 
 print $password . “ is the encrypted version of mypassword”;
$password = crypt('mypassword' , 'd4'); print $password . " is the CRYPT_STD_DES version of mypassword<br>"; 
$password = crypt('mypassword' , 'k783d.y1g'); print $password . " is the CRYPT_EXT_DES version of mypassword<br>"; 
$password = crypt('mypassword' , '$1$d4juhy6d$'); print $password . " is the CRYPT_MD5 version of mypassword<br>"; 
$password = crypt('mypassword' , '$2a$07$kiuhgfslerd...........$'); print $password . " is the CRYPT_BLOWFISH version of mypassword<br>"; ?> 
output:
d4/qPbCcJ5tD. is the CRYPT_STD_DES version of mypassword
k7xEagYCDPPSc is the CRYPT_EXT_DES version of mypassword
$1$d4juhy6d$a.jIPYnvne1FWF2V6mGQR0 is the CRYPT_MD5 version of mypassword
$2a$07$kiuhgfslerd...........6k0kSI76CqJ/RWGnSp9MWRDF91gJZfW is the CRYPT_BLOWFISH version of mypassword
As long as you always use the same salt the encrypted password should always be the same, making it a good solution for password storage.

Testing uploaded Data

<?php 
 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()) ; 
 mysql_select_db("Database_Name") or die(mysql_error()) ; 

 //Retrieves data from MySQL 
 $data = mysql_query("SELECT * FROM employees") or die(mysql_error()); 

//Puts it into an array

while($info = mysql_fetch_array( $data )) {

//Outputs the image and other data

Echo "<img src=http://www.yoursite.com/images/".$info['photo'] ."> <br>";

Echo "<b>Name:</b> ".$info['name'] . "<br> ";

Echo "<b>Email:</b> ".$info['email'] . " <br>";

Echo "<b>Phone:</b> ".$info['phone'] . " <hr>";

} ?>

To show the image, we just use normal HTML for the image, and only change the last part (the actual image name) with the image name stored in our database.

 

[error] phpmailer Could not instantiate mail function.

In Ubuntu (at least 12.04) it seems sendmail is not installed by default. You will have to install it using the command sudo apt-get install sendmail-bin

You may also need to configure the proper permissions for it as mentioned above.

$msg = nl2br(strip_tags($_POST['message']));
// Using the PHPMailer class
$mail = new PHPMailer();
$mail->IsMail();
// Adding the receiving email address
$mail->AddAddress($emailAddress);
$mail->Subject = 'AisforArt Feedback';
$mail->MsgHTML($msg);
$mail->AddReplyTo('noreply@'.$_SERVER['HTTP_HOST'], 'Quick Feedback');
$mail->SetFrom('noreply@'.$_SERVER['HTTP_HOST'], 'Quick Feedback');
$mail->Send();
echo 'Thank you!';

Few points to check:
1> is mail function disabled in your server?
This can be checked by using:

PHP Code:
mail("YourEmail@domain.com", "Test Subject", "Test Message");

2>is mail From param valid?

PHP Code:
$mail->From = $email;

3> did you try with SMTP?

PHP Code:
$mail->IsSMTP(); 

What is PHP_SELF variable?

PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder). You can use this variable in the action field of the FORM.

echo $_SERVER['PHP_SELF'];

a) Suppose your php file is located at the address:
http://www.yourserver.com/form-action.php

In this case, PHP_SELF will contain:
"/form-action.php"

b) Suppose your php file is located at the address:
http://www.yourserver.com/dir1/form-action.php

For this URL, PHP_SELF will be :
"/dir1/form-action.php"

php+javascript

Scanning for Photos with PHP

The photos are contained in two folders on the server – assets/photos/thumbs/ for the thumbnails, andassets/photos/large/ one for the full sizes. With PHP, we will scan the folders and output a JSON with the file names. You could alternatively return the images from a database, but you will have to keep the same structure.

// Scan all the photos in the folder $files = glob(‘assets/photos/large/*.jpg’);

$data = array();

foreach($files as $f){

$data[] = array(

‘thumb’ => str_replace(‘large’, ‘thumbs’, $f),

‘large’ => $f ); }

echo json_encode(array( ‘data’ => $data, ));

  1. First we will issue an AJAX GET request to fetch all the photos on disk from the PHP script.
  2. Then we will calculate how many photos to show on the page and their sizes, depending on the dimensions of the window, so that they fit perfectly.
  3. We will preload all the images that will be shown on the current page with a preloader script that uses jQuery deferreds. In the meantime, we will show the #loading div.
  4. After everything is loaded, we will generate the markup for the photos and add them to the #gallery element. Then we will trigger the diagonal fade animation and initialize the Swipebox gallery.
  5. When the user clicks on an arrow, we will repeat steps 3 and 4 (with either a top-left or a bottom-right animation).

The $.get() method loads data from the server using a HTTP GET request.

$.get(‘load.php’, function(response){
// response.data holds the photos
data = response.data;
// Trigger our custom data-ready event
gallery.trigger(‘data-ready’);
});

  • Request “test.php”, but ignore return results:
$.get(“test.php”);
  • Request “test.php” and send some additional data along with the request (ignore return results):
$.get(“test.php”, { name:”Donald”, town:”Ducktown” });
  • Request “test.php” and pass arrays of data to the server (ignore return results):
$.get(“test.php”, { ‘colors[]’ : [“Red”,”Green”,”Blue”] });
  • Request “test.php” and alert the result of the request:
$.get(“test.php”, function(data){
alert(“Data: ” + data);
});
The two main divs are #loading and #gallery. The first holds a loading gif, and the second the gallery photos. The#gallery div is set to position:fixed so it takes the entire width and height of the page. The markup for the photos themselves is just as simplistic:

$(‘#foo’).trigger(‘click’);

A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user:

 

Make an image gallery website using PHP and Mysql

How do I create a PHP/MySQL powered image gallery from scratch?

  1. Galleries need to be uploaded using Form and Browse(This i can find no Problem, just need it to be there to outline the steps)
  2. Need to have a thumbnail image created when a file is uploaded.
  3. How should it be structured in the Database, For example stored in DB as image or filename
<form enctype='multipart/form-data' action='CodeTool.php' method='POST'>
     File: <input name='picture' type='file'/>
     <input type='submit' value='Upload'/>
 </form>

Your form needs to have enctype='multipart/form-data' and the method needs to be POST. Then, to read the upload file, you can simply use the following. I’ve also added some basic validation to make sure that the file is an image:

 if(isset($_FILES['picture'])) {
     echo "File has been uploaded under temp file " . $_FILES['picture']['tmp_name'];
     // Let's check if the file is an image:
     $fileData = file_get_contents($_FILES['picture']['tmp_name']);
     // Using imagecreatefromstring, that way you don't need to guess the image format.
     if(($img = @imagecreatefromstring($fileData)) !== FALSE) {
         echo " and is a valid image";
     } else {
         echo " and is not a valid image";
     }
 }

imagecreatefromstring() returns an image identifier representing the image obtained from the given image. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.

To create a thumbnail image, you can use GD (or ImageMagick, but it is not included in the default configuration) as such… Let’s continue from the imagecreatefromstring if statement:

if(($img = @imagecreatefromstring($fileData)) !== FALSE) {
    // Let's create a 100x100 thumbnail
    $width = imagesx($img);
    $height = imagesy($img);
    $boxSize = min($width,$height);
    $boxX = ($width / 2) - ($boxSize / 2);
    $boxY = ($height / 2) - ($boxSize / 2);
    $thumb = imagecreatetruecolor(100, 100);
    imagecopyresampled($thumb, $img, 0, 0, $boxX, $boxY, 100, 100, $boxSize, $boxSize);
    //$thumb is now a 100x100 thumbnail
}

Question 3

Here you have 2 options. You can either store your images in the file system or in the database. To store your image in the file system, you can do the following:

if(($img = @imagecreatefromstring($fileData)) !== FALSE) {
    move_uploaded_file($_FILES['picture']['tmp_file'], 'somefile.jpg');
    // the code from the previous example
    imagejpeg($thumb, 'somefile_thumb.jpg');
}

I personally prefer using the database to store the images as it is easier to keep referential integrity and makes backup simpler (backup the database and you are done). It’s a bit slower, but the difference is really not that great:

if(($img = @imagecreatefromstring($fileData)) !== FALSE) {
    // the code from the previous example
    $tmp_thumb = tempnam(sys_get_temp_dir(), 'thumb');
    imagejpeg($thumb, $tmp_thumb);
    $thumbData = file_get_contents($tmp_thumb);
    mysql_query("INSERT INTO images (original, thumb) VALUES ('" . mysql_real_escape_string($fileData) . "', '" . mysql_real_escape_string($thumbData) . "');");
}

The fields needs to be BLOB.

mysql> CREATE TABLE tbl_images (
> id tinyint(3) unsigned NOT NULL auto_increment,
> image blob NOT NULL,
> PRIMARY KEY (id)
> );
A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements.

Reasons to store your images (binary files) in a database:

  • Storing in a database allows better security for your files and images.
  • Eliminates messy directory and file structures (this is especially true when users are allow to contribute files).
  • Files/Images can be stored directly linking to user or advertiser information.

You may want to reconsider storing your binary files in the database. Here are some reason you may not want to:

  • You can’t directly access your files using standard applications such as FTP.
  • If you database becomes corrupt, so do your files.
  • Migrating to a new database is made more difficult
  • Pulling images from a database and displaying them is slower than using file access.
 

create an image gallery website using php mysql

Simple PHP Photo Gallery Using Mysql

  • Mysql database to log uploads
  • Short description for the photos
  • Automatic thumbnail generation and resize on upload
  • ability to show the full sized pictures (used jQuery thickbox)

1. Sample database photo table contains three columns: id,photo_name and date_added

CREATE TABLE IF NOT EXISTS `photos` (
  `id` int(30) NOT NULL AUTO_INCREMENT,
  `photo_name` varchar(200) NOT NULL,
  `date_added` datetime NOT NULL,
  PRIMARY KEY (`id`)
  )

Build An Automated PHP Gallery System In Minutes

I know jQuery. Now what?

http://fredhq.com/projects/roundabout#/download


http://www.scriptiny.com/2011/03/javascript-modal-windows/

href=”#top”, connect to mysql

  • An anchor URL – points to an anchor within a page (like href=”#top“)

Putting the “#” symbol as the href for something means that it points not to a different URL, but rather to another id or name tag on the same page. For example:

<a href="#bottomOfPage">Click to go to the bottom of the page</a>
blah blah
blah blah
...
<a id="bottomOfPage"></a>

However, if there is no id or name then it goes “no where.”

database credentials in connect.php:

/* Database config */
$db_host = '';
$db_user = '';
$db_pass = '';
$db_database = '';
/* End config */
$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");

The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable.

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.

The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services.

Metadata is always passed as name/value pairs. The content attribute MUST be defined if the name or the http-equiv attribute is defined. if none of these are defined, the content attribute CANNOT be defined.

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Add a description" />
<meta name="keywords" content="Add keywords" />
<meta name="author" content="Codrops" />

HTML5 has a new attribute, charset, which makes it easier to define charset:

  • HTML 4.01: <meta http-equiv=”content-type” content=”text/html; charset=UTF-8″>
  • HTML5: <meta charset=”UTF-8″>

Differences Between HTML and XHTML

  • In HTML the <meta> tag has no end tag.
  • In XHTML the <meta> tag must be properly closed.

get the results with PHP/Mysql

$mysql_server = 'localhost';
$mysql_login = 'root';
$mysql_password = '';
$mysql_database = 'jQueryAutocomplete';

mysql_connect($mysql_server, $mysql_login, $mysql_password);
mysql_select_db($mysql_database);

$req = "SELECT name "
	."FROM mytable "
	."WHERE name LIKE '%".$_REQUEST['term']."%' "; 

$query = mysql_query($req);

while($row = mysql_fetch_array($query))
{
	$results[] = array('label' => $row['name']);
}

echo json_encode($results);

在使用 $_GET 变量时,所有的变量名和值都会显示在 URL 中。所以在发送密码或其他敏感信息时,不应该使用这个方法。不过,正因为变量显示在 URL 中,因此可以在收藏夹中收藏该页面。在某些情况下,这是很有用的。

注释:HTTP GET 方法不适合大型的变量值;值是不能超过 100 个字符的。

PHP 的 $_REQUEST 变量包含了 $_GET, $_POST 以及 $_COOKIE 的内容。

PHP 的 $_REQUEST 变量可用来取得通过 GET 和 POST 方法发送的表单数据的结果。

$_POST 变量用于收集来自 method=”post” 的表单中的值。

$_POST 变量

$_POST 变量是一个数组,内容是由 HTTP POST 方法发送的变量名称和值。表单域的名称会自动成为 $_POST 数组中的 ID 键

$_POST 变量用于收集来自 method=”post” 的表单中的值。从带有 POST 方法的表单发送的信息,对任何人都是不可见的(不会显示在浏览器的地址栏),并且对发送信息的量也没有限制。

为什么使用 $_POST?

  • 通过 HTTP POST 发送的变量不会显示在 URL 中。
  • 变量没有长度限制。

不过,由于变量不显示在 URL 中,所以无法把页面加入书签。

 
生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web