"shadows, post: 68547, member: 20311":
A lightweight script which I wrote today (Works with modern and older browsers IE 6+). You can create a new .JS, .PHP, and .CSS file to separate those, but I was lazy to do so, so here goes all together.
To include more data, you can change the line: [ICODE]$response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';[/ICODE]
The hard limit is that search query must have at least 4 characters (to avoid db stressing)
To do a quick test, create a new test.php file
<?php
include 'backend/functions.php';
dbconn();
// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$searchstr = strtolower(trim($_POST["query"]));
$search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4)
{
// You can JOIN tables here to get more information about torrents. (But will affect performance)
$stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
$row = mysqli_fetch_assoc($stmt);
}
}
echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #eee;padding-bottom: 5px;">Found results for <span style="color: #e6750c; ">' . $_POST['query'] . '</span></div>';
if ($row)
{
$response = '';
foreach ($stmt as $i)
{
$response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';
}
}
else
{
$response = '<div class="results">No results found</div>';
}
echo $response;
echo '</div>';
die;
}
stdhead('ajax search');
begin_frame('ajax search');
?>
Search torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>
<style>
.ls_box {
position: absolute;
background: #fff;
width: 20%;
border-bottom: 0;
border-radius: 10px;
padding: 10px;
box-shadow: 0 1px 4px rgba(0,0,0,.1);
font-weight: bold;
}
.results {
border-bottom: 1px solid #eee;
padding: 5px;
word-wrap: break-word;
}
.results a {
color: #111;
text-decoration: none;
}
.results a:hover {
color: #333;
}
.results:hover {
background: #e6750c3b;
border-right: 2px solid #e6750c;
}
</style>
<script type="text/javascript">
function ajaxSearch(str)
{
var xhttp;
if (str.length < 4) {
document.getElementById("ajaxSearchStatus").innerHTML= '';
return false;
}
// Modern browser support
if (window.XMLHttpRequest)
{
xhttp = new XMLHttpRequest();
}
// Old browser support (IE 6+)
else
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = '?ajax=1';
var params = 'query=' + str;
xhttp.open("POST", url, true);
// Send the proper header information along with the request
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// What to do with the response
xhttp.onreadystatechange = function()
{
if (this.readyState === 4 && this.status === 200)
{
document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
}
};
// Send the post fields
xhttp.send(params);
// Until data returned, show custom text
document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Loading data...</div>';
}
</script>
<?php
end_frame();
stdfoot();
Preview:
<?php
require_once('backend/functions.php');
dbconn();
// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$searchstr = strtolower(trim($_POST["query"]));
$search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4) //4 characters minum (to avoid db stressing)
{
// You can JOIN tables here to get more information about torrents. (But will affect performance)
$stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
$row = mysqli_fetch_assoc($stmt);
}
}
echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #B2B2B2;padding-bottom: 5px;color:#222;">Résultats trouvés pour <span style="color: blue; ">' . $_POST['query'] . '</span></div>';
if ($row)
{
$response = '';
foreach ($stmt as $x)
{
$response .= '<div class="results"><a href="/torrents-details.php?id=' . $x['id'] . '">' . $x['name'] . '</a></div>';
}
}
else
{
$response = '<div class="results" style="cOlor:black;"><i>...Aucun Résultat Trouvé!</i></div>';
}
echo $response;
echo '</div>';
die;
}
stdhead('ajax search');
begin_frame('ajax search');
?>
Rechercher des torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>
<style>
.ls_box {
position: absolute;
background: #fff;
width: 20%;
border-bottom: 0;
border-radius: 10px;
padding: 10px;
box-shadow: 0 1px 4px rgba(0,0,0,.1);
font-weight: bold;
}
.results {
border-bottom: 1px solid #eee;
padding: 5px;
word-wrap: break-word;
}
.results a {
color: #111;
text-decoration: none;
}
.results a:hover {
color: #333;
}
.results:hover {
background: #e6750c3b;
border-right: 2px solid #e6750c;
}
</style>
<script type="text/javascript">
function ajaxSearch(str)
{
var xhttp;
if (str.length < 4) {
document.getElementById("ajaxSearchStatus").innerHTML= '';
return false;
}
// Modern browser support
if (window.XMLHttpRequest)
{
xhttp = new XMLHttpRequest();
}
// Old browser support (IE 6+)
else
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = '?ajax=1';
var params = 'query=' + str;
xhttp.open("POST", url, true);
// Send the proper header information along with the request
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// What to do with the response
xhttp.onreadystatechange = function()
{
if (this.readyState === 4 && this.status === 200)
{
document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
}
};
// Send the post fields
xhttp.send(params);
// Until data returned, show custom text
document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Chargement des données...</div>';
}
</script>
<?php
end_frame();
stdfoot();
// start id3
echo "<div id=id3 style=display:none;>";
#begin_frame(T_("UPLOADED_TORRENTS"));
//page numbers
$page = (int) $_GET["page"];
$perpage = 25;
$where = "";
if ($CURUSER['control_panel'] != "yes")
$where = "AND anon='no'";
$res = SQL_Query_exec("SELECT COUNT(*) FROM torrents WHERE owner='$id' $where");
$row = mysqli_fetch_array($res);
$count = $row[0];
unset($where);
$orderby = "ORDER BY id DESC";
//get sql info
if ($count) {
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "account-details.php?id=$id&");
$query = "SELECT torrents.id, torrents.category, torrents.leechers, torrents.nfo, torrents.tube, torrents.tube2, torrents.sticky, torrents.seeders, torrents.name, torrents.times_completed, torrents.size, torrents.added, torrents.comments, torrents.numfiles, torrents.filename, torrents.owner, torrents.external, torrents.freeleech, categories.name AS cat_name, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, torrents.anon, torrents.uplreq, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating, torrents.announce FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN users ON torrents.owner = users.id WHERE owner = $id $orderby $limit";
$res = SQL_Query_exec($query);
}else{
unset($res);
}
if ($count) {
print($pagertop);
torrenttable($res);
print($pagerbottom);
}else {
print("<b>".T_("UPLOADED_TORRENTS_ERROR")."</b><br />");
}
#end_frame();
}
echo "</div>";
// end id3
<!-- Css new look login-->
<link rel="stylesheet" href="<?php echo $site_config["SITEURL"]; ?>/themes/default/css/normalize.css">
<link rel="stylesheet" href="<?php echo $site_config["SITEURL"]; ?>/themes/default/css/style.css">
<!-- New look login -->
<script type="text/javascript" src="<?php echo $site_config["SITEURL"]; ?>/js/prefixfree.min.js"></script>
//BEGIN FRAME
function begin_frame($caption = "-", $align = "justify"){
global $THEME, $site_config;
$blockId = 'f-' . sha1($caption);
print("<div id='fade-box'><div class='myFrame'>
<div class='myFrame-caption'>$caption<a style='float:right; clear:right;' href='#' class='showHide' id='$blockId'></a></div>
<div class='myFrame-content'>
<div class='slidingDiv$blockId'>");
}
//END FRAME
function end_frame() {
global $THEME, $site_config;
print("</div></div>
<div class='myFrame-foot'></div>
</div></div>
<br />");
}
"phoenix75, post: 68532, member: 1185":
this is new login js
ps:hello spiritblue could you improve it ?
"m-jay, post: 68460, member: 20288":
This mod is complete in that it does what it is intended to do ?
Ive placed in progress because it might need some fine tuning now we use the database for sessions its more secure but also we can start playing with the data, this is where testing will help the cleanup for example you could wipe tables on cleanups.
The base mod has two session uid (user id) & pass (hashed password, id, ip, secret) again this is somewhere things can be added
Members can login with session which closes when browser close
[ATTACH type="full" alt="session.png"]5490[/ATTACH]
Members can click remember for session login cookie which last 1 month
[ATTACH type="full" alt="cookie.png"]5491[/ATTACH]
if anyone plays with this can you please share any work or examples
sql
create table sessions(
id serial,
sess_id text not null,
_access integer,
data text,
primary key (id)
);
in account-login.php find
$password = $_POST['password'];
add below
$testing = $_POST['rememberme'];
find
if (!$message){
replace that old code with this (just after show error)
if (!$message){
// Session Handler
setsess($row["id"], $row["password"], $row["secret"]);
if( isset($_POST['rememberme']) ){
logincookie($row["id"], $row["password"], $row["secret"]);
setsess($row["id"], $row["password"], $row["secret"]);
}
header("Location: index.php");
}else {
show_error_msg(T_("ACCESS_DENIED"), $message, 1);
}
find
<tr><td align="center"><b><?php echo T_("PASSWORD"); ?>:</b> <input type="password" size="40" name="password" /></td></tr>
add below
<tr><td align="center"><input type="checkbox" name="rememberme" value="rememberme" /> Remember Me</td></tr>
in account-logout.php find
deconn();
add under
// Remove cookies & sessions
session_destroy();
in functions.php replace logincookie & logout cookie with
// Obtain / Create session Cookie Function
function logincookie($id, $password, $secret, $updatedb = 1, $expires = 0x7fffffff)
{
// get sess_id
$sid = session_id();
// store only sess_id
setcookie("PHPSESSID", $sid, time()+ 30*30*60*60, "/"); // one month
// maybe add session in cleanup
if ($updatedb) {
SQL_Query_exec("UPDATE users SET last_login = '".get_date_time()."' WHERE id = $id");
}
}
// Cookie Destruction function
function logoutcookie()
{
// get sess_id
$sid = session_id();
// reset cookie to session
setcookie("PHPSESSID", $sid, "0", "/");
}
function setsess($id, $password, $secret)
{
// encrypt pass
$hash = $id . $secret . $password . getip() . $secret;
// set session handler
$_SESSION['uid'] = $id;
$_SESSION['pass'] = $hash;
}
find
function dbconn($autoclean = false){
add under
// Session Handler
require "classes/Session.php";
[/code]
now the userlogin function for auth
// Check The Cookies and Sessions details
if (!$_SESSION["pass"] || !is_numeric($_SESSION["uid"])) { // todo
logoutcookie();
return;
}
//Get User Details And Permissions
$res = SQL_Query_exec("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id=$_SESSION[uid] AND users.enabled='yes' AND users.status = 'confirmed'");
$row = mysqli_fetch_assoc($res);
$hash = $row["id"] . $row["secret"] . $row["password"] . $ip . $row["secret"];
if (!$row || !$_SESSION['pass'] == $hash){
logoutcookie();
return;
} else {
// success - need else to match hash & session above
}
Session.php (the class)
<?php
class Session {
private $pdo;
public function connect() {
global $site_config;
// create a db connection
$pdo = new PDO('mysql:host='.$site_config['mysql_host'].';dbname='.$site_config['mysql_db'], $site_config['mysql_user'], $site_config['mysql_pass']);
return $pdo;
}
public function _open() {
$this->pdo = Session::connect();
if ($this->pdo) {
return true;
}
else {
return false;
}
} // end function _open()
public function _close() {
$this->pdo = null;
return true;
} // end function _close()
public function _read($sess_id) {
if (!$this->pdo) {
$this->pdo = Session::connect();
}
$sql = "select data from sessions where sess_id=:sess_id";
$statement = $this->pdo->prepare($sql);
$statement->execute(array(':sess_id' => $sess_id));
$num = $statement->rowCount();
if ($num == 1) {
$row = $statement->fetch(PDO::FETCH_ASSOC);
$data = $row["data"];
return $data;
}
else {
return ''; // return empty string if no data returned
}
} // end function _read()
public function _write($sess_id,$data) {
$access = time();
$sql = "select * from sessions where sess_id=:sess_id";
$statement = $this->pdo->prepare($sql);
$statement->execute(array(':sess_id' => $sess_id));
$num = $statement->rowCount();
if ($num === 0) {
$sql = "insert into sessions (sess_id, _access, data) values ".
"(:sess_id,:access,:data)";
$statement2 = $this->pdo->prepare($sql);
$myArray = array();
$myArray[':sess_id'] = $sess_id;
$myArray[':access'] = $access;
$myArray[':data'] = $data;
$statement2->execute($myArray);
if ($statement2 === false) {
return false;
}
else {
// new data stored
return true;
}
} // end case of inserting new session data
else {
$sql = "update sessions set _access = :access, " .
"data = :data where sess_id = :sess_id";
$statement2 = $this->pdo->prepare($sql);
$myArray = array();
$myArray[':sess_id'] = $sess_id;
$myArray[':access'] = $access;
$myArray[':data'] = $data;
$statement2->execute($myArray);
if ($statement2 === false) {
return false;
}
else {
// data updated
return true;
}
} // end case of updating existing record
} // end function _write()
public function _destroy($sess_id) {
$sql= "delete from sessions where sess_id=:id";
$statement = $this->pdo->prepare($sql);
$statement->execute(array(':id' => $sess_id));
if ($statement === true) {
return true;
}
else {
return false;
}
} // end function _destroy()
public function _gc($max) {
$old = time() - $max;
$sql = "delete from sessions where _access < :old";
$statement = $this->pdo->prepare($sql);
$statement->execute(array(':old' => $old));
if ($statement === true) {
return true;
}
else {
return false;
}
} // end function _gc
}
$sess = new Session();
session_set_save_handler(
array($sess,'_open'),
array($sess,'_close'),
array($sess,'_read'),
array($sess,'_write'),
array($sess,'_destroy'),
array($sess,'_gc')
);
register_shutdown_function('session_write_close');
/*
// change php.ini
ini_set('session.cookie_lifetime', 60 * 60 * 24 * 90); // 3months
ini_set('session.gc_maxlifetime', 60 * 60 * 24 * 90); // 3 months
*/
// start
session_start();
?>
// Check The Cookies and Sessions details
if (!$_SESSION["pass"] || !is_numeric($_SESSION["uid"])) { // todo
logoutcookie();
return;
}
//Get User Details And Permissions
$res = SQL_Query_exec("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE id=$_SESSION[uid] AND users.enabled='yes' AND users.status = 'confirmed'");
$row = mysqli_fetch_assoc($res);
$hash = $row["id"] . $row["secret"] . $row["password"] . $ip . $row["secret"];
if (!$row || !$_SESSION['pass'] == $hash){
logoutcookie();
return;
} else {
// success - need else to match hash & session above
}
"STorrents2020, post: 68518, member: 20382":
just personal preference, the last mod I posted I’ve corrected all tags before post
"shadows, post: 68160, member: 20311":
jackett is a very powerful application and is maintained daily by their staff
[URL unfurl="true"]https://github.com/Jackett/Jackett[/url]
Users make scripts which will automate access to your torrent site, but yes it will eat your resources if you do not protect your site against it.
PS: I use jackett and contribute to it.
/* Flash text by spiritblue */
#flash{
animation: Test 3s infinite; /* Speed in seconds */
}
@keyframes Test{
0%{opacity: 1;}
50%{opacity: 0;}
100%{opacity: 1;}
}
<div id="flash"> TESTING </div>"STorrents2020, post: 68344, member: 20382":
Pay attention to the error. Confirm your database details. Do you have mysql_pdo installed? I should of added checks...