Permalink
Browse files

split out database config into its own file

  • Loading branch information...
1 parent c23f60e commit bd5616e4cff04ebb2ebad6f27e32d5198ed7ab23 = committed Feb 26, 2012
Showing with 18 additions and 37 deletions.
  1. +4 −9 config.php
  2. +11 −0 db_config.php
  3. +3 −3 index.php
  4. +0 −25 recentlinks.php
View
@@ -5,12 +5,7 @@
* Contact the author at http://briancray.com/
*/
-// db options
-define('DB_NAME', 'your db name');
-define('DB_USER', 'your db usernae');
-define('DB_PASSWORD', 'your db password');
-define('DB_HOST', 'localhost');
-define('DB_TABLE', 'shortenedurls');
+require('db_config.php');
// connect to database
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
@@ -23,7 +18,7 @@
define('LIMIT_TO_IP', $_SERVER['REMOTE_ADDR']);
// change to TRUE to start tracking referrals
-define('TRACK', FALSE);
+define('TRACK', TRUE);
// check if URL exists first
define('CHECK_URL', FALSE);
@@ -37,5 +32,5 @@
// if so, where will the cache files be stored? (include trailing slash)
define('CACHE_DIR', dirname(__FILE__) . '/cache/');
-// if so, where will the cache files be stored? (include trailing slash)
-define('SHOW_RECENT', FALSE);
+// change to TRUE if you want to show recent links on the main page
+define('SHOW_RECENT', TRUE);
View
@@ -0,0 +1,11 @@
+<?php
+
+// db options
+define('DB_NAME', 'your_db_name');
+define('DB_USER', 'your_db_username');
+define('DB_PASSWORD', 'your_db_password');
+define('DB_HOST', 'your_db_hostname');
+define('DB_TABLE', 'shortenedurls');
+
+
+?>
View
@@ -3,14 +3,14 @@
<title>URL shortener</title>
<meta name="robots" content="noindex, nofollow">
</head>
-<body onload="loadRecentLinks()">
+<body <?php if(SHOW_RECENT){echo 'onload="loadRecentLinks()"';}?>>
<h1><?php echo $_SERVER['HTTP_HOST'];?></h1>
<form method="post" action="shorten.php" id="shortener">
<label for="longurl">URL to shorten</label> <input type="text" name="longurl" id="longurl"> <input type="submit" value="Shorten">
</form>
-</form>
+
@@ -62,7 +62,7 @@
<script type="text/javascript">
function loadRecentLinks()
{
- $.getJSON("recentlinks.php",
+ $.getJSON("getrecentlinksJSON.php",
function(data)
{
$.each(data, function(index)
View
@@ -1,25 +0,0 @@
-<?php
-
-require('config.php');
-
-$query = 'select long_url, referrals from ' . DB_TABLE . ' order by created desc limit 20';
-
-$result = mysql_query($query);
-
-echo recordSetToJson($result);
-
-function recordSetToJson($mysql_result)
-{
- $data = array();
- while($row = mysql_fetch_array($mysql_result))
- {
- $data[] = array ('long_url'=>$row['long_url'], 'referrals'=>$row['referrals']);
- }
- return json_encode($data);
-}
-
-?>
-
-
-
-

0 comments on commit bd5616e

Please sign in to comment.