Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Using the Personalization Script

By Blair Ireland
Senior Editor, TheScripts.com

All thats really left is to show you all a simple way of putting this info into a normal page. Here we go....

<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("users");

Connecting to the MySQL database.....

if ($site_user and $site_pass) {
$query = mysql_query("SELECT * FROM personalize WHERE(Name='$site_user' AND Password='$site_pass')");
$info = mysql_fetch_array($query);
}

We don't want to waste any memory or CPU power if the person doesn't even have the cookie yet. Since PHP pre-parses cookies provided via the http request, it assigns them in their own variables. Our cookies were named site_user and site_pass, so these are the cookies we look for to see if they exist. If they do, we execute the query.

There is one new function you will see below, include. In short, the include() statement includes and evaluates the specified file. In our case, we are using it from the file system so we specify the full path to the directory containing our news PHP files.

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> Personalized Page For <?php echo $info['Name'] ?></TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<TABLE BORDER=0>
<TR>
    <TD>
    <TABLE BORDER=0>
    <TR>
        <TD><?php include("/full/path/to/news/".$info['News1']); ?></TD>
    </TR>
    <TR>
        <TD><?php include("/full/path/to/news/".$info['News2']); ?></TD>
    </TR>
    <TR>
        <TD>
            <a href="http://oap.weather.com/fcgi-bin/oap/redirect_magnet?loc_id=<?php echo $info['Weather'] ?>&par=internal&site=magnet&code=10001&promo=english">
            <img border=0 width=270 height=140 src="http://oap.weather.com/fcgi-bin/oap/generate_magnet2?loc_id=<?php echo $info['Weather'] ?>&code=10001">
        </TD>
    </TR>
    </TABLE>
    </TD>
    <TD>Content Here;</TD>
</TR>
</TABLE>
</BODY>
</HTML>

And we are finished. This tutorial should have taught you the basic methods to accomplish user personalization on your site. Modifications will nearly always follow these methods, and our examples were only to get you started. If you go to Linux.com, Yahoo or anything else with personalization, you will probably be shocked to see that all of these sites use these very same methods, whether for showing you weather, stocks, or even targeted ads.

When you make the experience for your user a little more exciting and interactive, your odds of having them return increase exponentially giving you a greater user base.... plus personalization is just a cool thing to have.