PHP
  Home arrow PHP arrow Page 3 - Developing a User Personalization System with PHP and Cookies
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

Developing a User Personalization System with PHP and Cookies
By: Duncan Lamb
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek