weird behavior in including files

i have a weird problem in including files in php, i have a functions.php file in a folder and a Router in the index.php file, when i include thefunctions.php in the index.php, all the other pages that rely on it get broken, the variables become empty and the functions no longer work, when i dont include it in the index.php file all the other pages function normally

i include my files in all pages in this way

require_once($_SERVER["DOCUMENT_ROOT"] . "/src/logic/functions.php");

my other pages are in /src/pages/

i have tried all ways of including the file but i keep getting the same problem, i need to include the functions.php in the index file to use some of its functions.

i do have a declare(strict_types=1) in the index file if that affects it

Any help will be appreciated thanks.

reddit.com
u/Available_Hippo4035 — 6 days ago

file not being deleted after its expiry time passes

Hello, im trying to make a rate limiting function that prevent users from using specific forms when they reach a certain threshold and the limit will get reset after a certain amount of time, when a user submits a request, a file with their ip will get created into a cache folder and the amount of requests is inside the file, the rate limiting works except the file doesnt get deleted after the specified amount of time passes, any help will be appreciated. Thanks!

rate_limiter.php

<?php
ignore_user_abort(true);
//Get the user IP
function getIP() {
$ip = null;
if(!empty($_SERVER["REMOTE_ADDR"])) {
$ip = $_SERVER["REMOTE_ADDR"];
} elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}

return $ip;
}

function rate_limit($ip, $requests_limit, $limit_expiry) {
$start_time = null;
$reached_limit = null;
$amount_requests = 1;
$file_name = __DIR__ . "/cache/ratelimit-" . $ip;
$file_name = rtrim($file_name);
if(!file_exists($file_name)) {
global $start_time;
$start_time = time();
$fp = fopen($file_name, "w+") or die("An error occured");
fwrite($fp, $amount_requests) or die("Failed to write into file");
fclose($fp);
} elseif(file_exists($file_name)) {
$fp = fopen($file_name, "r+") or die("Failed to read file");
$new_amount_requests = file_get_contents($file_name);
if($new_amount_requests >= $requests_limit) {
global $reached_limit;
echo "<script>alert('You have been rate limited!')</script>";
$reached_limit = true;
header("Location: /", 423, true);
} elseif(!$reached_limit) {
$new_amount_requests++;
ftruncate($fp, 0);
fwrite($fp, $new_amount_requests) or die("Failed to write amount of requests");
}
}

if(file_exists($file_name) && time() - $start_time >= time() + $limit_expiry) {
unlink($file_name);
}




}

?>

index.php

<?php
ignore_user_abort(true);
require_once("rate_limiter.php");

if(isset($_POST["submit"])) {
$ip_Addr = getIP();
rate_limit($ip_Addr, 3, 60);
echo $_POST["text"];
}

?>
reddit.com
u/Available_Hippo4035 — 8 days ago

Difference between pwm and single wire pwm

Hello, im having trouble trying to understand the difference between pwm (the same one used to control led brightness, non-PWM fans) and single wire pwm (like in pc fans where the pwm is a single wire), i thought pwm is used to control electronics through positive and negative and not a single wire. Im asking this to control a pwm server fan without a pc Any help will be appreciated thanks! ​​​

reddit.com
u/Available_Hippo4035 — 15 days ago
▲ 1 r/Motors

What is single wire pwm on fans?

Hello, im having trouble trying to understand the difference between pwm (the same one used to control led brightness, non-PWM fans) and single wire pwm (like the one in pc fans where the pwm is a single wire), i thought pwm is used to control electronics through positive and negative and not a single wire. Im asking this to control a pwm server fan without a pc Any help will be appreciated thanks! ​​​

reddit.com
u/Available_Hippo4035 — 15 days ago

Overheating after thermal paste change on laptop

I changed my laptops cpu thermal paste, before changing the temps were around 70°c playing games, but after the thermal paste change its now 90°c

I used a zalman stc-8 on the cpu

The laptop's model is ​ınfinix inbook x1

I tightened the screws diagonally but didn't overturn, any help will be appreciated ​

u/Available_Hippo4035 — 17 days ago