Archive for the ‘Articles’ Category
Filed Under (Articles, PHP Code Samples) by Virender on May-29-2007
Cookies and Sessions both fulfill the purpose of storing data across the pages of a website. Both have their own advantages. Cookies are stored on the client side and can be set to a long lifespan, which means that data stored in a cookie can be stored for months if not years. Cookies work fine with a web application installed on a cluster of web server, whereas sessions are stored on the server, means if one web server is handling the request, the other web server on the cluster will not have access to the information stored. As Sessions are stored on web server, this gives extra security and freedom. We do not transmit session data with each page, just an ID and the data is loaded from the local file stored on the server. Clients do not know about the information we store about them, which is not the case with Cookies. Many browsers have a limit for the Cookies as to stop the wastage of bandwidth that is caused by meaningless Cookies, but that is not the case with Sessions. They are stored on the server, hence they can be of any size. One can use them as per requirement. If he wants to store information until visitor comes back next day then Cookies are the way to go. If some part of cookie data is crucial then we can store it in database and just store an ID in the Cookie to reference the data. If not, then use Sessions, as they are little easier to use and do not require their entire data to be sent with each page. Sessions get cleaned as soon as visitor closes the web browser. Let’s see how to use Cookies in a web page The following script will store a Cookie labeled test on the client side with a value as “IsOn”. Please make sure that you set cookie values before sending any output to browser. Code (php) <?php setcookie("test", "IsOn", time() + (60 * 60));// variable name = test, value = "IsOn" and cookie life is one minute from current time. If you don't set cookie life, it will be expired after browser is closed. ?> Now that our Cookie is set up, we can use it on every page of the site. If the above code shows nothing in output, then consider it as cookies being disabled or cookies improperly set. As you can see, we access information stored in cookies by using $_COOKIE[] array. To destroy Cookies forcefully, we can use the following script: Code (php) <?php setcookie("test", "IsOn", time() - (60 * 60)); // setting a cookie life to a time that is past will actually expire the cookie instantly ?> Now, let’s see how to use Sessions in a web page: Code (php) <?php session_start(); // this needs to be declared on the top of every page, specially before sending any output to the browser. $_SESSION['Check'] = 'test'; echo $_SESSION['Check'];// displays "test" on any page of that web site ?> We can use sessions on same page. Since sessions are server-side and the users have access to only the Session Identifier. To destroy the Sessions for the current site, we can use the following script.
Filed Under (Articles, Technology Junk) by Anoop on May-23-2007
PICO accomplished!!! Confused? Don’t be. PICO is the name of Yahoo’s Web based Messenger’s Mission. Yahoo has launched the BETA version of its Web based Messenger on 3rd May, 2007. It is easy to use, fast and has a cool interface with no download required. It consists of all basic features like chat, add friends, stealth mode, smilies, text formatting and the most useful feature “chat historyâ€. Now you just need an internet connection to get started with yahoo Messenger, no downloads required. Just go through http://webmessenger.yahoo.com or simply type http://web.im from your browser and you are ready to go. Feedbacks from initial users are coming great. They are pleased to see Yahoo’s web based messenger. Meebo already has a combined web based messenger that worked with industry leading messengers AOL, MSN, Yahoo, Google talk. Yahoo web messenger is compatible with all the browsers like IE, Firefox, Opera, Netscape and safari etc. Yahoo has again done a great job just like Yahoo Mail Beta. Yahoo Web messenger beta lacks some important features in comparison to desktop messenger such as file transfer, webcam, Chat rooms, Voice chat etc. But still it provides most of the necessary features required for key communication and self expressive features you need. Thumbs up to Yahoo’s new initiative. We have already discussed, how to install apache and php on windows. Now in this post we are going to tell you that how can you install and configure mysql and server to make it work. Download Our Configuration
Setup
MySQL Server Binaries MySQL ships with a number of server binaries to choose from. For standard/typical use and functionality, the preference is for server binary ‘mysqld-nt’. Server binaries with the ‘-nt’ suffix should only be used under Windows NT/2000/XP/2003.
Startup MySQL can be installed as a Service (automatic or manual start-up) or started as a standalone console application. The MySQL server can be configured to listen (and communicate) on all interfaces (0.0.0.0), the loopback (127.0.0.1), or any other address. The MySQL server can also be configured to skip networking (TCP/IP) and/or connect via named-pipes (sockets). Install the MySQL process as a Service. Other options (edit my.ini), section ‘[mysqld]‘, insert… Start the MySQL Service… Start MySQL as a standalone console application. C:\www\mysql\bin> mysqld-max-nt –standalone –console Cleanup Create a password for the ‘root’ mysql account… Display all databases, accounts, and access controls to individual databases… Remove all initial accounts except ‘root@localhost’; remove ‘test’ database and privileges set… mysql> DELETE FROM mysql.user WHERE User=”; mysql> DELETE FROM mysql.user WHERE User=’root’ AND Host != ‘localhost’; mysql> DROP DATABASE test; mysql> DELETE FROM mysql.db WHERE Db = ‘test’ OR Db = ‘test\\_%’; mysql> FLUSH PRIVILEGES; Note: Cleanup only if you are a advance user. Any extra modification can result in the mysql startup failer. Because mysql also consists of additional information with itself. Cleanup processor is not a neccassory task. Running MySQL All commands are run from the command line and directory C:\www\mysql\bin (unless the mentioned dir is under the PATH) Enter the command-line interface… Stop the MySQL Service (one of two ways)… Uninstall the MySQL Service… Shutdown the standalone console MySQL application (one of two ways)… Help All commands are run from the command line and directory C:\www\mysql\bin (unless the mentioned dir is under the PATH) Display mysql-max-nt options… Display MySQL version information… See what values a running MySQL server is using… Display information… Update password for MySQL user ‘root’ (from the MySQL shell)… Source : http://www.devside.net Step 1 - Download the Latest stable snapshot version. Although this is a ‘Stable’ snapshot - it is still a snapshot and not a recommended release for production purposes. I am providing this tutorial because all stable production release versions from 5.1.x and below do not work with the latest stable release of Apache 2.2.2. Go to http://snaps.php.net/ and download the latest stable Win32 Package. This tutorial assumes you will want to install the latest version 5 snapshot build which at the time of writing is 5.2. For this tutorial I used the snapshot built on 29th June 2006. You should use the latest snapshot dated the same day as you download it. Click on the latest version ‘ php5.2 (zip) ‘ to download the file named ‘ php5.2-win32-2006xxxxxx.zip ‘ - 8.4MB, save it to your hard drive in a suitable temporary location. (In case of re-installs being necessary I have a permanent location called ‘Master Programs’ where I download to and extract from there). [xxxxxx being the date of the latest version] Step 2 - Install PHP Following on from our previous related tutorial on Apache, extract/copy all files and sub-folders to ‘C:\Apache2\php5′ - if you extract elsewhere e.g - ‘D:\PHP5\’ , please remember to substitute this file path in any future references. Note: PHP5 Installation is slightly different to PHP4 installations. You can find install.txt in PHP4 directory which will help you to install PHP 4 very easilly. The php5 install.txt has this to say :- Upgrading from a previous PHP version: Previous editions of the manual suggest moving various ini and DLL files into your SYSTEM (i.e. C:\WINDOWS) folder and while this simplifies the installation procedure it makes upgrading difficult. We advise you remove all of these files (like php.ini and PHP related DLLs from the Windows SYSTEM folder) before moving on with a new PHP installation. Be sure to backup these files as you might break the entire system. The old php.ini might be useful in setting up the new PHP as well. And as you’ll soon learn, the preferred method for installing PHP is to keep all PHP related files in one directory and have this directory available to your systems PATH. Locate C:\Apache2\php5\phi.ini-recommended and make a copy of this file, rename it to php.ini and make sure it is saved in the same folder.
Step 3 - Configure PHP 5.2-dev for Apache 2.2.2 Edit your newly copied php.ini in notepad and scroll down to the ‘Paths and Directories’ section.
Save and Close php.ini. Step 4 - Configure Apache 2.2.2 for PHP 5.2-dev ————– Locate all the LoadModule entries near the top of the file and just below them add :- # For PHP 5 do something like this: Ensure the path to the php5apache2_2.dll and to the PHP directory reflect your setup, not neccessarily what I have above. Note that the dll we want here is called php5apache2_2.dll and not the php5apache2.dll that earlier versions of PHP came with. The rest of ‘httpd.conf’ should be ok if the earlier tut was followed, so Save and Close this file then ‘Stop and Start’ or ‘Restart’ the Apache Server service. Ok, so lets get testing! Step 5 - Testing your Installation. Open Notepad (or whatever) and paste the following code into it:- <?php phpinfo(); ?> and save the file as phpinfo.php Open your browser and go to ‘ http:\\localhost\phpinfo.php ‘ With a bit of luck you should have a screen full of Server related information and variables. If not, something has gone wrong with the installation somewhere, It is usually a simple config error or path related problem and nothing serious. Thanks for listening, the next article in this series of Articles is to install and configure mySQL for use with Apache 2.2.2 and PHP 5.2-dev. Important Note: This tutorial recommends and uses php.ini-recommended as a starting point when learning PHP. It has a lot of ’safe’ features & settings by default. In particular the ’short_open_tags’ setting is off meaning you can not open a PHP tag with just a <? but you must you the full <?php to start off any PHP code segments.
Filed Under (Articles) by Anoop on May-11-2007
Step 1 - Download the latest version of Apache. Goto http://httpd.apache.org/download.cgi and look for the latest stable release. This is currently 2.2.2 and is the version we will use here. Click the link "apache_2.2.2-win32-x86-no_ssl.msi" and Save to an appropriate part of your hard drive. The hard part is done ;) Step 2 - Install Apache Double-click the downloaded MSI to launch the installer. You will be presented with the welcome screen. Step 3 - Lets Configure our new Server. These instructions configure the Server for SSI as well as taking the ‘VirtualHosts’ approach. This enables you to then add more web sites as needed just by configuring a new ‘VirtualHost’ for each. PHP config options will be added in the PHP tutorial section . Below instructions assume ‘yoursite.com’ as the site name, change to suit yours!! Locate and edit ‘httpd.conf’ file (should be in ‘C:\Apache2\Apache2\conf\httpd.conf’) ServerRoot, ServerName, DocumentRoot etc will all have been pre-set according to what information you provided in the intial installation phase. Check these and it is ok to change them manually if your setup needs or locations change. Locate this code near the bottom of the file :- <Directory /> and just below it add a new directory container for your base websites files locations.
<Directory "d:/accounts/*/"> In the above example, this is needed to configure the directory structure for where our virtual hosts will be placed on the server - and this for security reasons is outside of the directory structure for the web server apache files themselves. Here I have created a directory called ‘accounts’ where all websites will be based beneath. Find the code section:-
<IfModule dir_module> and make it look like this :-
Find the section :- # Filters allow you to process content before it is sent to the client. and uncomment out those last two lines to read :- # Filters allow you to process content before it is sent to the client. ————– There is now a supplementary section near the bottom of httpd.conf which gives you the option to include extra configuration files into your setup. In our case, the virtualHosts that we want to configure, instead of doing so at the bottom of this httpd.conf file, we instead enable the ‘httpd-vhosts.conf’ file and do our configurations in there. Still in httpd.conf file , find the section which is headed by :-
# Supplemental configuration and then find these two lines of code :-
# Virtual hosts Uncomment out the second line to enable the external vhosts file :-
# Virtual hosts Ok, we are done with httpd.conf file but we are not done configuring. We now need to edit /extra/httpd-vhosts.conf and configure our virtual host containers. Save and Close ‘httpd.conf’ file. Locate and edit ‘httpd-vhosts.conf’ file (should be in ‘..\conf\extra\httpd-vhosts.conf’) then create a new VirtualHost container for your first site (yoursite.com). <VirtualHost *> The first VirtualHost container block - or the only container block - is also the fallback default virtualhost should any other requests not be found. More information on configuring VirtualHost containers is at http://httpd.apache.org/docs/2.2/vhosts/ Ok so that about it, Save the file, then ‘Stop’ and ‘Start’ the Server again. Check that the default site is now our new VirtualHost by going to http://localhost in your browser. Of course you will already have some files including an index page in d:/accounts/yoursite/ or you’ll get a 404 error.
Step 4 - Extra Configurations. Enable the local Manual again! Edit your httpd.conf file and locate :- # Local access to the Apache HTTP Server Manual Lets enable the manual by removing the comment from the second line. # Local access to the Apache HTTP Server Manual Ok, good thats it, restart the Apache Server service and go to http://localhost/manual and you should have your manual showing again! If you get an Access Denied message, have a look in ../conf/extra/httpd-manual.conf and check that the location specified in the Alias Match and Manual lines points to the location of the manual directory. Disable external access to the Manual You may not care about this, but if you do here is how to disable external access to your manual. Edit your ../conf/extra/httpd-manual.conf file and locate in the Directory configuration :- Allow from all Change this to read :- Allow from localhost Restart your Server. Now http://locahost/manual will still work, but http://yoursite.com/manual will not. You can enhance this to allow the whole of your local network access, certain external IP addresses etc etc. |
|