User:Allen4names/Random Archive Query

I have created a PHP script that should be given the file name RandomArchiveQuery.php. Preliminary tests of this script have been done but you may want to have

I have created a PHP script that should be given the file name RandomArchiveQuery.php. Preliminary tests of this script have been done but you may want to have someone with more experience look this over and make changes. Configuration variable have been included so that common changes can be made quickly and easily as shown in the script below.

<?php
#	Random Archive Query - Redirects a query for an archived URL to a random archive.
#	Copyright (C) 2011  [email protected]

#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2 of the License, or
#	(at your option) any later version.

#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.

#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

## Set configuration variables.
# Set to 'true' for plain URLs or 'false' for encoded URLs.
$usePlainURL = true;
# Refresh delay in seconds.
$refreshDelay = '5';

## Print XHTML header. Change the title as needed.
print '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Random Archive Query - [email protected]</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<!-- Bots should not archive, follow links, or index this page. -->
<meta name="robots" content="noarchive,nofollow,noindex" />';

# Get the query string and verify.
$pageURL = $_SERVER['QUERY_STRING'];
if ( substr($pageURL,0,4) == 'url=' ) {
	$pageURL = substr($pageURL,4);
} else {
	$pageURL = '';
}
# Test to see if the url value has been set.
if ( $pageURL != '' ) {
	# Pick an archive at random.
	$randomArchive = rand(1,3);
	if ( $randomArchive == 1 ) {
		# Internet Archive - Original: 'http://web.archive.org/web/*/'. Beta: http://waybackmachine.org/*/'.
		if ( $usePlainURL ) {
			$queryArchiveURL = 'http://waybackmachine.org/*/'.$pageURL;
		} else {
			$queryArchiveURL = 'http://waybackmachine.org/*/'.urldecode($pageURL);
		}
	} elseif ( $randomArchive == 2 ) {
		# WebCite
		if ( $usePlainURL ) {
			$queryArchiveURL = 'http://www.webcitation.org/query?url='.urlencode($pageURL);
		} else {
			$queryArchiveURL = 'http://www.webcitation.org/query?url='.$pageURL;
		}
	} elseif ( $randomArchive == 3 ) {
		# Wikiwix
		if ( $usePlainURL ) {
			$queryArchiveURL = 'http://wikiwix.com/cache/?url='.urlencode($pageURL);
		} else {
			$queryArchiveURL = 'http://wikiwix.com/cache/?url='.$pageURL;
		}
	}
	# Print a meta refresh tag.
	print '<meta http-equiv="refresh" content="'.$refreshDelay.';'.$queryArchiveURL.'" />';
	# Set success flag.
	$RAQstatus = true;
} else {
	# Set failure flag.
	$RAQstatus = false;
}
print '
</head>
<body>
<h1>Random Archive Query</h1>';
if ( $RAQstatus ) {
print '
<p>This page will redirect you to '.$queryArchiveURL.' in '.$refreshDelay.' seconds.</p>';
} else {
	if ( $usePlainURL ) {
		$exampleURL = 'http://www.example.org/'; # Plain URL
	} else {
		$exampleURL = 'http%3A%2F%2Fwww.example.org%2F'; # Encoded URL
	}
print '
<p>The <tt>url</tt> value needs to be set. An example is shown below.</p>
<pre>http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'].'?url='.$exampleURL.'</pre>';
}
print '
</body>
</html>';
?>

A copy of the GNU General Public License, Version 2 is included with the MediaWiki software.

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.