- Impact
- 1,273
Here is the code:
What I want to do is, instead of a redirect of the traffic that goes to these short URLs, to be forwarded to a page with a frame on top that I can place ads on.
Code:
<?php
ob_start();
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Short URLs by EPH.LI | JOS.EPH.LI | Joseph Slabaugh</title>
<style type="text/css">
<!--
body {
font-family:Geneva, Arial, Helvetica, sans-serif;
font-size:0.9em;
}
a, a:hover, a:visited {
color:#d20000;
}
form {
padding:15px;
margin:0;
border:1px solid #dddddd;
width:50%;
}
form label {
font-weight:bold;
padding-right:10px;
}
form input {
border:1px solid #dddddd;
border-right:2px solid #cccccc;
border-bottom:2px solid #cccccc;
padding:4px;
}
form input.button {
background-color:#D20000;
font-weight:bold;
font-size:0.8em;
color:#ffffff;
border:1px solid #FF0505;
border-right-color:#9E0000;
border-bottom-color:#9E0000;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
//-->
</style>
</head>
<body>
<?php
/*
*
* script by spyka Webmaster - www.spyka.net
* version 1.0.2
* copyright (c) 2008 spyka Web Group
* license http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0
* support: http://www.spyka.net/forums
*
*/
/*
location of file to store URLS
*/
$file = 'urls.txt';
/*
use mod_rewrite: 0 - no or 1 - yes
*/
$use_rewrite = 1;
/*
language/style/output variables
*/
$l_url = 'URL';
$l_nourl = '<strong>No URL supplied</strong>';
$l_yoururl = '<strong>Your short url:</strong>';
$l_invalidurl = '<strong>Invalid URL supplied.</strong>';
$l_createurl = 'Make shorter!';
//////////////////// NO NEED TO EDIT BELOW ////////////////////
if(!is_writable($file) || !is_readable($file))
{
die('Cannot write or read from file. Please CHMOD the url file (urls.txt) by default to 777 and make sure it is uploaded.');
}
$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';
$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";
$output = '';
if($action == 'create')
{
if(isset($_POST['create']))
{
$url = trim($_POST['url']);
if($url == '')
{
$output = $l_nourl;
}
else
{
if(eregi($valid, $url))
{
$fp = fopen($file, 'a');
fwrite($fp, "{$url}\r\n");
fclose($fp);
$id = count(file($file));
$dir = dirname($_SERVER['PHP_SELF']);
$filename = explode('/', $_SERVER['PHP_SELF']);
$filename = $filename[(count($filename) - 1)];
$shorturl = ($use_rewrite == 1) ? "http://{$_SERVER['HTTP_HOST']}{$dir}/{$id}" : "http://{$_SERVER['HTTP_HOST']}{$dir}/{$filename}?id={$id}";
$output = "{$l_yoururl} <a href='{$shorturl}'>{$shorturl}</a>";
}
else
{
$output = $l_invalidurl;
}
}
}
}
if($action == 'redirect')
{
$urls = file($file);
$id = trim($_GET['id']) - 1;
if(isset($urls[$id]))
{
header("Location: {$urls[$id]}");
exit;
}
else
{
die('Script error');
}
}
//////////////////// FEEL FREE TO EDIT BELOW ////////////////////
?>
<?include('ads.php');?>
<center><b>EPH.LI URL shortner by Joseph Slabaugh</b>
<!-- start html output -->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p class="response"><?=$output?></p>
<p>
<label for="s-url">URL:</label>
<input id="s-url" type="text" name="url" />
</p>
<p>
<input type="submit" class="button" name="create" value="<?=$l_createurl?>" />
</p>
</form>
<?include('ads.php');?>
<p>This is a service of Jos.eph.li and <a href="http://jos.eph.li">Joseph Slabaugh</a></p>
<p>Find some of the links that have been shortened below</p>
<p>Want to stop paying your cable bill?! <a href="http://www.cutmycablecosts.com">Cut my cable costs now</a>!</p>
<p></p>
<?include('ads.php');?>
<p><strong>Warning, not responsible for any links on that file. They are non-clickable, but they are not approved by the administrator. <a href="http://www.slabaugh.org/contact">Report abusive links</a></strong></p>
</center>
<IFRAME src="http://www.slabaugh.org/eph.li/urls.txt" width="100%" height="300"
scrolling="auto" frameborder="1">
<!-- end html output -->
</body>
</html>
<?php
ob_end_flush();
?>
What I want to do is, instead of a redirect of the traffic that goes to these short URLs, to be forwarded to a page with a frame on top that I can place ads on.