Store session data in MongoDB with PHP

MongoDB is scalable document oriented database. This make it a good choice to store of the session information of the users. With MongoDB, your application can grow as the users grows, for example, a Social Network Site.

A special cookie with a name "SID" is used to identify the current session. To start a session , first check the cookie, if there is a cookie named with "SID", then load the session data from MongoDB, if not, create a new session and insert a record that contains session data into database.

A special cookie with a name "SID" is used to identify the current session. To start a session , first check the cookie, if .

Regular expression non-capture in PHP

The non-capture parentheses is a confusing regular expression element. The non-capture operator has a special notation (?:).

Here is an example in PHP:

Advance query in MongoDB with PHP

In last post we demonstrate the basic CRUD in MongoDB. Lets get some advanced query technique.

MongoDB support chained calling, you can filter result by chaining, to select the first 3 recoreds:

CRUD in Mongodb with PHP

In last post we introduced how to install mongodb and the php extension on windows.

Lets do some CRUD operation in PHP script.

PHP install PEAR and mongodb on windows

Install PEAR is very easy, just download http://pear.php.net/go-pear.phar and run

Then you can install mongodb like this:

PHP tutorial : How to output category tree

A very common situation in web development is the category tree, in its nature , its just a recursive traversal of a tree data structure. This post will demonstrate the method of generating a tree while traversing the data strucute.

Step 1. Create a database table to store the category data:

PHP example: How to get extension of a file name

A typical file name in windows is like "file.txt". How to get the extension name with php script?

If you think its too many lines:

Upload files to FTP server with php script recursively

PHP has built in networking api to access all kinds of services. Here is a script you can type in a command line window to upload a folder and all its sub directories to a FTP server. Sometimes it will be very handy with a command to do this kind of job.

Using php record visitor information

Its very useful to record the site visitor information like ip address, search keywords, visit url...

Today I will write a simple php script to achieve that. First we need a database table to store the information. Here is the table:

PHP Zoom image, code example

How to zoom image in php? Here is a quick recipe.

 
 
<?php
 
list($image_width, $image_height) = @getimagesize('xx.jpg');
$imgsrc = imagecreatefromjpeg('xx.jpg');
$towidth = 565;
$newwidth = $towidth ;
$newheight = ($image_height * $towidth )/$image_width;
$imgdst = imagecreatetruecolor($newwidth , $newheight );
 
$copy = @imagecopyresized($imgdst, $imgsrc, 0, 0, 0,0, $newwidth , $newheight , $image_width, $image_height );
 
imagejpeg($imgdst, 'yy.jpg');
imagedestroy($imgsrc);
imagedestroy($imgdst);
?>
 
Previous Page 1 ... 3 4 5 Next Page