PHP
  Home arrow PHP arrow Page 3 - Developing a User Personalization Syst...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Developing a User Personalization System with PHP and Cookies
By: Duncan Lamb
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    1999-09-20

    Table of Contents:
  • Developing a User Personalization System with PHP and Cookies
  • Grabbing Headlines
  • User Login
  • Reading from Cookies
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing a User Personalization System with PHP and Cookies - User Login


    (Page 3 of 5 )

    Now a form should be built to enter information, make choices, and then enter the data in the database. Here's a simple form with a few more choices available:


    <HTML> <HEAD> <TITLE>Login now!</TITLE> </HEAD> <BODY> <br>Choose the headlines you wouldlike to see!<br> <form method=post action="newuser.php3"> <br> Please pick a login name:<input name="login" type="TEXT" value=""> <br> Now pick a password:<input name="password" type="TEXT" value=""> <br><br> <br>News Choice 1:<SELECT NAME="news1" size=5 value=""> <option value="slashdot.lnk">Slashdot <option value="freshmeat.lnk">Freshmeat <option value="voodooextreme.lnk">VoodooExtreme <option value="devshed.lnk">DevShed <option value="bluesnews.lnk">Blue's News </select> <br>News Choice 2:<SELECT NAME="news2" size=5 value=""> <option value="slashdot.lnk">Slashdot <option value="freshmeat.lnk">Freshmeat <option value="voodooextreme.lnk">VoodooExtreme <option value="devshed.lnk">DevShed <option value="bluesnews.lnk">Blue's News </select> <br>News Choice 3:<SELECT NAME="news3" size=5 value=""> <option value="slashdot.lnk">Slashdot <option value="freshmeat.lnk">Freshmeat <option value="voodooextreme.lnk">VoodooExtreme <option value="devshed.lnk">DevShed <option value="bluesnews.lnk">Blue's News </select> <br><input type="submit" name="Submit" value=" Submit "> <br></FORM> </BODY> </HTML>

    The action in the form is "newuser.php3." Once data has been entered in the form, this script inserts a new row of data in the database.


    <? SetCookie("visitor",$login,time()+864000); ?> <HTML> <HEAD><TITLE>Thanks!</TITLE></HEAD> <BODY> <? mysql_connect("localhost", "username", "pass") or DIE("Unable to connect to database"); @mysql_select_db("project") or die("Unable to select database"); $result = mysql_query("Select * from users where login='$login'"); if(!mysql_numrows($result)) { #Make a new login - entire page follows $result = mysql_query("insert into users values ( '$login', '$password', NOW(), '$news1', '$news2', '$news3')"); ?> <br> Thanks for logging in!<br><br> To see what the page looks like with your personal settings, please <a href="index.php3">return</a>. <? } else { echo "Whoa! Someone has already picked that username!<br><br>"; echo "Please hit the back button and pick a unique login."; } ?> </body> </html>

    Notice that "Setcookie" command? We'll talk about on the next page. For now, notice how the database is checked for duplicate logins first (lines 10), then a new row is created (line 12). Afterwards, a link to the start page is given.

    At the end of the script, the user gets some feedback if his login is not unique.

    Normally to pass variables to any sort of script, variables have to be added to the end of the URL, but what we want is a simple solution, so whenever a user comes to the page, their preferences will be displayed without any mumbo jumbo at the end of the url. We still need a way to pass our scripts information about the user. The best way to do so is with cookies, and nothing handles cookies as easily as PHP3.

    More PHP Articles
    More By Duncan Lamb


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT