Miscellaneous Code
  Home arrow Miscellaneous Code arrow Fake Error
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS CODE

Fake Error
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2002-06-18

    Table of Contents:

    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


    Fake error is a small joke-script I wrote. It creates a generic Apache web-server page that lists random folders.

    The script is designed to run on Apache webservers, but it could possibly be modifed to run on rival systems. The script uses random names, dates, and numbers. You can specify the names of the folders, and how many folders are listed on each page (an option for a random numbers is available). Sample code for MySQL error logging is included.

    By : RobertDX

    <?php
    // Script Name: Fake Error
    // Author: Robert Baird
    /* Description:
    Fake error is a small joke-script I wrote. It creates a generic Apache web-server page that lists random folders. The script is meant to be used in combination with a .htaccess file, so error pages are redirected to this script.

    Lets say you have a protected folder on your website called "includes", instead of just denying the public access to this directoy, you can give them a fake page to look at. While they're there, you can be logging their IP address, the time, and how long they try to view the directory.

    The script has some MySQL code (turned off by default), which can be customized to whatever type of database you prefer.

    The script is designed to run on Apache webservers, but it could possibly be modifed to run on rival systems. The script reads a list of folder names from an array, creates random timestamps for the modification dates, and creates random folder sizes. You can specify the names of the folders, and how many folders are listed on each page (an option for a random number of folders is available).

    See http://baremetal.com/gadgets/htaccess/ for help on setting up a .htaccess file.

    Trademarked names such as Apache are held by Apache Software Foundation, code is copyrighted by Robert Baird.
    */

    // This is the array of random folder names. If a name selected is longer than 23 characters it will be trunciated
    $namelist = array("images", "documents", "programs", "utilities", "system folder", "publishing", "games");

    // set the mininum number of folders to be created
    $min = 2;

    // set the maximum number of folders to be created
    $max = 8;

    /*
    This is the mysql code I use on my server:

    // connect to db
    $db = mysql_connect("localhost", "username", "password");

    // select the database
    mysql_select_db("databasename", $db);

    // program out the SQL INSERT
    $sql = "INSERT INTO errors (time, ip, URI) VALUES (NOW(), '" . $_SERVER['REMOTE_ADDR'] . "', '" . $_SERVER['REQUEST_URI'] . "')";

    // execute SQL command
    $result = @mysql_query($sql);
    */

    // nothing below this line needs to be modified normally

    // this is a list of months to use in the random timestamp
    $monthlist = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

    // set $pos to the position of the "." in the URI
    $pos = strpos($_SERVER['REQUEST_URI'], ".");

    // if there is a "." a specific file has been attempted to be accessed
    if ($pos) {

    // create a new URI that removes the "." and everything after it
    $newuri = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], "."));

    // redirect to the new URI
    header("Location: http://" . $_SERVER['SERVER_NAME'] . $newuri);
    exit;

    };

    // set $pos to the position of the "?" in the URI
    $pos = strpos($_SERVER['REQUEST_URI'], "?");

    // if there is a "?" in the URI delete it and everything after it
    if ($pos) {

    // creating the new URI
    $newuri = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], "?"));

    // redirect to the new URI
    header("Location: http://" . $_SERVER['SERVER_NAME'] . $newuri);
    exit;

    };

    // if the current URI ends in a "/"
    if ((strrpos($_SERVER['REQUEST_URI'], "/") + 1) == strlen($_SERVER['REQUEST_URI'])) {

    // get rid of the trailing "/"
    $newuri = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], "/"));

    // redirect to the new URI
    header("Location: http://" . $_SERVER['SERVER_NAME'] . $newuri);
    exit;

    }

    // the following HTML is default for the Apache webserver
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Index of <?php print($_SERVER['REQUEST_URI']); ?></TITLE>
    </HEAD>
    <BODY>
    <H1>Index of <?php print($_SERVER['REQUEST_URI']); ?></H1>
    <PRE>
    <IMG SRC="http://<?php print($_SERVER['SERVER_NAME']); ?>/icons/blank.gif" ALT=" "> <A HREF="<?php print($_SERVER['REQUEST_URI']); ?>/?N=D">Name</A> <A HREF="<?php print($_SERVER['REQUEST_URI']); ?>/?M=A">Last modified</A> <A HREF="<?php print($_SERVER['REQUEST_URI']); ?>/?S=A">Size</A> <A HREF="<?php print($_SERVER['REQUEST_URI']); ?>/?D=A">Description</A>
    <HR>
    <IMG SRC="http://<?php print($_SERVER['SERVER_NAME']); ?>/icons/back.gif" ALT="[DIR]"> <A HREF="http://<?php print($_SERVER['SERVER_NAME']); ?>">Parent Directory</A> 10-Jun-2002 15:37 -
    <?php

    // run this loop a random number of times, using the $min and $max the user specified above
    $a = rand($min,$max);
    for ($i=0; $i < $a; $i++) {

    // the name is a random name in the namelist
    $name = array_rand($namelist);
    $name = $namelist[$name];

    // the month is a random month in the monthlist
    $month = array_rand($monthlist);
    $month = $monthlist[$month];

    // the day is a random number from 1 to 30 (yes I know some months have 31 and 29 days, even 28 sometimes, but this isn't that elaborate of a script
    $day = rand(1,30);

    // the year is a random number from 1997 to 2002, you can expand this to go further back in time or into the future if you'd like
    $year = rand(1997,2002);

    // using the 24 hour timesystem the hour is a random number between 0 and 23
    $hour = rand(0,23);

    // minutes is a random number between 0 and 59
    $minutes = rand(0,59);

    // filesize is a random number between 1 and 999 (it could be larger in real life...)
    $filesize = rand(1,999);

    // if the random name selected is longer than 23 characters, cut it after the 23 character
    if (strlen($name) > 23) {
    $namecut = substr($name, 0, 23);
    }

    // for consistancy we use the name $namecut from now on for the cut name, even if it wasn't cut
    else {
    $namecut = $name;
    }

    // if $day only has one digit (1-9), add a preceding 0 to the number to match the format
    if (strlen($day) == 1) {
    $day = "0" . $day;
    }

    // same for the hour, add a 0 if it's only one digit in length
    if (strlen($hour) == 1) {
    $hour = "0" . $hour;
    }

    // same for the minutes, add a 0 if it's only one digit in length
    if (strlen($minutes) == 1) {
    $minutes = "0" . $minutes;
    }

    // if the file name did not take up all 23 characters, we need to add some space
    if (strlen($name) != 23) {
    $space = str_pad("", (23 - strlen($namecut)));
    }

    // again with the number padding, this time add two spaces to the filesize if its only one digit in length
    if (strlen($filesize) == 1) {
    $filesize = " " . $filesize;
    }

    // add only one space to the filesize if its already two digits in length
    if (strlen($filesize) == 2) {
    $filesize = " " . $filesize;
    }

    // construct the entire line
    print("<IMG SRC=\"http://" . $_SERVER['SERVER_NAME'] . "/icons/folder.gif\" ALT=\"[DIR]\"> <A HREF=\"http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "/" . $name ."\">$namecut</A>$space $day-$month-$year $hour:$minutes " . $filesize . "k<br>");

    // go back to the start of the for-loop, recreate the random names and numbers, print out all the needed lines
    }

    ?>
    </PRE><HR>
    <?php print($_SERVER["SERVER_SIGNATURE"]); ?></BODY></HTML>
    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 Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! IBM – Taking Web 2.0 to Work

    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!


    NEW! Applying lean thinking to the governance of software development

    Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Webcast: IBM Rational Build Forge - Beyond the Build

    The discipline of assembling and delivering software is maturing beyond standard developer-centric compile/test software builds. The end-to-end software development lifecycle is emerging as the new focus moves “Beyond the Build.” Join this on demand webcast to learn about methods for streamlining software delivery and key capabilities of the IBM Rational Build Forge framework for automating build and release management in environments of any size.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...





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