From dcb05f3e31eccfd734f8c536813cdd51971ceaec Mon Sep 17 00:00:00 2001 From: Edoardo Date: Sun, 12 Dec 2021 14:26:19 +0100 Subject: [PATCH] Add files via upload --- index.php | 32 ++++++++++++++++++++++---------- redirect.php | 31 +++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/index.php b/index.php index c485a98..6047817 100644 --- a/index.php +++ b/index.php @@ -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) { @@ -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); diff --git a/redirect.php b/redirect.php index 87e51b7..8e46f5f 100644 --- a/redirect.php +++ b/redirect.php @@ -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"); } } ?> \ No newline at end of file