Removed database initialization code and instead used the function defined in db.inc.php
This commit is contained in:
15
checkloc.php
15
checkloc.php
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
require_once 'db.inc.php';
|
||||
if (isset($_SESSION['glink']) && !empty($_SESSION['glink'])) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
} else {
|
||||
http_response_code(403);
|
||||
die('Forbidden.');
|
||||
}
|
||||
// FUNCTION TO CALCULATE HAVERSINE DISTANCE GIVEN COORDINATES OF
|
||||
// TWO POINTS, AND RADIUS (IN KM)
|
||||
function haversine_distance($lat1, $long1, $lat2, $long2, $radius) {
|
||||
@@ -36,9 +44,8 @@
|
||||
$user_long = $user_long * (M_PI / 180);
|
||||
$glink = $_GET["glink"];
|
||||
|
||||
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
||||
$keyspace = 'glink';
|
||||
$session = $cluster->connect($keyspace);
|
||||
$session = init_cass_db();
|
||||
|
||||
$statement = $session->prepare('SELECT latitude,longitude,radius,url FROM data WHERE shortlink=? ALLOW FILTERING;');
|
||||
$result = $session->execute($statement,array('arguments' => array($glink)));
|
||||
|
||||
|
10
redirect.php
10
redirect.php
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
require_once 'db.inc.php';
|
||||
ini_set("session.cookie_secure",1);
|
||||
session_start();
|
||||
use Cassandra;
|
||||
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
@@ -7,13 +10,11 @@
|
||||
$matches_uri = preg_match('/^[a-zA-Z]+$/',$uri);
|
||||
|
||||
if (($matches_uri == 0) || ($matches_uri == false)) {
|
||||
header("Location: http://glink.zip/");
|
||||
header("Location: https://glink.zip/");
|
||||
exit;
|
||||
} else {
|
||||
|
||||
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
||||
$keyspace = 'glink';
|
||||
$session = $cluster->connect($keyspace);
|
||||
$session = init_cass_db();
|
||||
|
||||
$statement = $session->prepare('SELECT url,is_geo FROM data WHERE shortlink=? ALLOW FILTERING;');
|
||||
$result = $session->execute($statement,array('arguments' => array($uri)));
|
||||
@@ -29,6 +30,7 @@
|
||||
exit;
|
||||
} else {
|
||||
if ($row['is_geo'] == true) {
|
||||
$_SESSION['glink'] = $uri;
|
||||
header("Location: https://glink.zip/reqloc.html?glink=" . $uri);
|
||||
exit;
|
||||
} else {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once 'db.inc.php';
|
||||
|
||||
function gen_base62_rand_shortlink($len) {
|
||||
$rand_bytes = random_bytes(intval(($len * 2) / 3));
|
||||
@@ -29,9 +30,7 @@ function gen_rand_shortlink($len) {
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
||||
$keyspace = 'glink';
|
||||
$session = $cluster->connect($keyspace);
|
||||
$session = init_cass_db();
|
||||
|
||||
$url = $_GET["url"];
|
||||
|
||||
|
Reference in New Issue
Block a user