This will count your outgoing hits so you know where people are going from your site. This was created quickly to manage outgoing hits, perhaps it'll be of some use. I heavily commented it so hopefully all will understand its logic. It is a very simple script. It just tracks url and number of hits.
By : philip
A new version of this lives here :
http://www.theprojects.org/scripts/linkTracker/
<?php
// : Filename : go.php
// : Version 0.0.1d
// Me : Philip Olson @ theprojects.org
// : Do whatever you want, just don't take credit as your own.
// : NO CREDIT REQUIRED. :-) This is simple, all should learn to
// create such a script, which is why it is so commented :-)
// Use : <a href="go.php?url=www.google.com">google</a>
// : Will insert url name and hit count into database.
// : Manages outgoing hit count.
// Set : mysql table name hits and url. hits is integer about 8chars
// and url is to hold at least the length of your longest linked
// url, set to about or at least 80chars.
// Ex : CREATE TABLE url_redirect (
// url varchar(100) NOT NULL,
// hits int(10) DEFAULT '1' NOT NULL,
// PRIMARY KEY (url)
// );
//
// TODO: Error checking does not exist and should / will in version .2
// If you want a version .2 then email author and ask!
/*-----------------------------------------------------------------
BEGIN USER CONFIGURATIONS
-----------------------------------------------------------------*/
// If go.php is called directly, goes to default_url.
$default_url = 'www.theprojects.org';
// Your database settings. You should include these from a secure
// location (out of your web root) but it's up to you :-)
$db_host = 'localhost'; // usually localhost
$db_name = '';
$db_user = '';
$db_pass = '';
$db_table = ''; // table holding url and hits fields.
// Debug TRUE or FALSE. If you're debuggin, set to TRUE
$debug = FALSE;
/*-----------------------------------------------------------------
END USER CONFIGURATIONS
------------------------------------------------------------------*/
// Db connect function
function db_connect()
{
global $db_host,$db_name,$db_user,$db_pass,$db_table,$connected;
global $err;
$conn = mysql_connect($db_host, $db_user, $db_pass);
if ($conn) {
$db_link = mysql_select_db($db_name,$conn);
if ($db_link) {
$connected = TRUE;
} else {
$err .= '[Db not being selected]';
}
} else {
$err .= '[Db not being connected]';
}
}
// This connects to db. In future consider more 'useful' placement
// for this function.
db_connect();
// If $url is not empty then process request
if (!empty($url)) {
// If connected to database then insert info into database otherwise
// just redirect url.
if ($connected) {
$msg .= '[$connected is TRUE, database being query\'d]';
// Select current hit count from db where field url equals url
$r = mysql_query ("select hits from $db_table WHERE url='$url'");
// Return the results from above query
$hits = @mysql_result($r,0);
// If not yet in database (0 hits) then insert new url, value=1 hit
if ($hits == 0) {
$q = "INSERT INTO $db_table (url,hits) VALUES('$url','1')";
// Else use current hit count plus 1 as we just got a hit
} else {
$q = "UPDATE $db_table SET hits = $hits+1 WHERE url='$url'";
}
// And finally, put info into the database
mysql_query($q);
}
// Else $url is empty so set as default $host
} else {
$url = "$default_url";
}
// If debug is TRUE then show debug information and do not redirect.
if ($debug) {
print '<li>$url is ' . $url;
print '<li>$hits is ' . $hits;
print '<li>$q is ' . $q;
print '<li>db_connect is ' . print db_connect();
// If $msg and $err are not empty then print them out.
if (!empty($msg)) { print '<li>Messages are ' . $msg; }
if (!empty($err)) { print '<li>Errors are ' . $err; }
} else {
// Do redirection. To be paranoid (for no good reason), clear
// cache first.
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Pragma: no-cache");
header ("Cache-Control: no-cache, must-revalidate");
header ("Location: http://$url");
exit;
}
// Email me questions, will most likely answer them.
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Link Farm Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |