Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed0ardo authored Dec 12, 2021
1 parent d3dc259 commit dcb05f3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
32 changes: 22 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,32 @@
die("Connection failed: " . mysqli_connect_error());
}

function get_result( $Statement ) {
$RESULT = array();
$Statement->store_result();
for ( $i = 0; $i < $Statement->num_rows; $i++ ) {
$Metadata = $Statement->result_metadata();
$PARAMS = array();
while ( $Field = $Metadata->fetch_field() ) {
$PARAMS[] = &$RESULT[ $i ][ $Field->name ];
}
call_user_func_array( array( $Statement, 'bind_result' ), $PARAMS );
$Statement->fetch();
}
return $RESULT;
}

$longURL = $_POST['longURL'];

$stmt = $mysqli->prepare("SELECT code FROM associations WHERE link=?");
$stmt->mysqli_bind_param("s",$longURL);
$stmt = $conn->prepare("SELECT code FROM associations WHERE link=?");
$stmt->bind_param("s",$longURL);
$stmt->execute();
$result = $stmt->get_result();
$result = get_result($stmt);
$stmt->close();

if($result->num_rows){

$result = mysqli_fetch_assoc($result);

if(count($result)){
mysqli_close($conn);
header("Location: https://xx.xx/sl/result?code=" . $result["code"]);
header("Location: https://ed0.it/sl/result?code=" . $result[0]["code"]);
}
else{
function generateRandomCode($length = 6) {
Expand All @@ -46,9 +58,9 @@ function generateRandomCode($length = 6) {
$row = mysqli_num_rows($result);
}
while($row);
$stmt = $mysqli->prepare("INSERT INTO associations (code, link)
$stmt = $conn->prepare("INSERT INTO associations (code, link)
VALUES (?, ?)");
$stmt->mysqli_bind_param("ss", $code, $longURL);
$stmt->bind_param("ss", $code, $longURL);

if ($stmt->execute()) {
mysqli_close($conn);
Expand Down
31 changes: 23 additions & 8 deletions redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT link FROM associations WHERE code='".$_GET["code"]."'";
$result = mysqli_query($conn, $sql);

$row = mysqli_num_rows($result);
function get_result( $Statement ) {
$RESULT = array();
$Statement->store_result();
for ( $i = 0; $i < $Statement->num_rows; $i++ ) {
$Metadata = $Statement->result_metadata();
$PARAMS = array();
while ( $Field = $Metadata->fetch_field() ) {
$PARAMS[] = &$RESULT[ $i ][ $Field->name ];
}
call_user_func_array( array( $Statement, 'bind_result' ), $PARAMS );
$Statement->fetch();
}
return $RESULT;
}

if($row){
$result = mysqli_fetch_assoc($result);
$stmt = $conn->prepare("SELECT link FROM associations WHERE code=?");
$stmt->bind_param("s",$_GET["code"]);
$stmt->execute();
$result = get_result($stmt);
$stmt->close();

if(count($result)){
mysqli_close($conn);
header("Location: " . $result["link"]);
header("Location: " . $result[0]["link"]);
}
else{
header("Location: https://xx.xx/sl");
mysqli_close($conn);
header("Location: https://ed0.it/sl");
}
}
?>

0 comments on commit dcb05f3

Please sign in to comment.