Skip to content

Instantly share code, notes, and snippets.

@fliiiix
Last active February 19, 2018 13:59
Show Gist options
  • Save fliiiix/4578968 to your computer and use it in GitHub Desktop.
Save fliiiix/4578968 to your computer and use it in GitHub Desktop.
my simple link list NEW with mysqli Do What The Fuck You Want To Public License
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Linkliste</title>
<style type="text/css">
h3 { margin-bottom: 0px; }
#mainDiv { margin: auto; width: 800px;}
</style>
</head>
<body>
<div id="mainDiv">
<h1>Linklist</h1>
<p>
Da ich bisher meine Links immer in Textdateien auf irgendwelchen blätter aufgeschrieben hab um sie dann zu vergessen hab ich mich entschlossen,
mir was kleine zu bauen wo ich meine Links rein werfend kann. Und das ist dabei herausgekommen. Ich übernehme keine Haftung für die Links!
</p>
<?php
#variable
$sqlHost = "localhost";
$sqlUser = "link";
$sqlPasswort = "xxxxxxxx";
$sqlDBname = "links";
$con = new mysqli($sqlHost, $sqlUser, $sqlPasswort, $sqlDBname);
if ($con->connect_errno) {
die('Keine Verbindung möglich: ' .$con->connect_error);
}
#login
if(isset($_POST["name"]) && isset($_POST["passwort"])){
$query = "SELECT * FROM user WHERE name=\"" . mysqli_real_escape_string($con, $_POST["name"]) . "\" AND passwort=\"" . crypt(mysqli_real_escape_string($con, $_POST["passwort"]), '$6$rounds=9999$xxxxxxxlzzzzyyyy$') . "\" AND Aktiv=1";
$ergebnis = $con->query($query);
if (!$ergebnis) {
die('Konnte Abfrage nicht ausführe');
}
if(mysqli_num_rows($ergebnis) == 1){
$_SESSION["userHasLogin"] = TRUE;
}
else {
echo 'fail!';
}
}
#loginForm
if(isset($_GET["login"])){
echo '<form action="/links/index.php" method="post">
<input type="text" name="name" id="name"/>
<input type="password" name="passwort" id="email"/>
<input type="submit" value="Einloggen" id="login_button" name="login_button"/>
</form>';
}
#logout
if(isset($_GET["logout"])){
$_SESSION["userHasLogin"] = FALSE;
}
#postForm
if(isset($_SESSION["userHasLogin"])){
if ($_SESSION["userHasLogin"] == TRUE){
echo '<form action="/links/index.php?post" method="post">
<input type="text" name="link" id="link"/>
<input type="submit" value="Save" id="save_button" name="save_button"/>
</form>';
}
}
#handelpost
if(isset($_GET["post"]) && isset($_POST["link"])){
$query = "INSERT INTO link (datum, link, aktiv) VALUES(\"" . date("Ymd") . "\",\"" . mysqli_real_escape_string($con, $_POST["link"]) . "\",1);";
if ($con->query($query) == FALSE) {
die('Konnte Abfrage nicht ausführe');
}
echo 'okey';
}
#renderContent
$query = "SELECT * FROM `link` WHERE aktiv = 1 ORDER BY datum DESC LIMIT 2000";
$ergebnis = $con->query($query);
if (!$ergebnis) {
die('Konnte Abfrage nicht ausführe');
}
$vorherigesDatum = NULL;
while ($row = $ergebnis->fetch_assoc()) {
if($row["datum"] != $vorherigesDatum){
if($row["datum"] == date("Y-m-d")){
echo '<h3>Heute</h3>';
}
else {
$dayArray = explode('-', $row["datum"]);
echo '<h3>' . $dayArray[2] .'.' . $dayArray[1] .'.' . $dayArray[0] . '</h3>';
}
}
echo '<a href="' . $row["link"] . '">' . $row["link"] . '</a> <br />';
$vorherigesDatum = $row["datum"];
}
$ergebnis->free();
?>
</div>
</body>
</html>
<?php mysqli_close($con) ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment