facing problem with xampp

am new to php and i was working in signup sysytem but when i try to see my work i face this error does anyone know the solution i search in the net and i try what i found but nothing work with me
No description
40 Replies
Jochem
Jochem•15mo ago
That is almost always an error in your code somewhere, a more detailed error should be available in the PHP Error log if you're using an IDE with syntax checking, there's actually probably a red squiggle somewhere in the file you're trying to open too
ItsAmjed
ItsAmjedOP•15mo ago
i got this mssg but idk what mean or where i look
No description
ItsAmjed
ItsAmjedOP•15mo ago
i can show u all my codes + idk what IDE mean
Jochem
Jochem•15mo ago
the log is more useful, can you copy/paste (instead of screenshot) the messages before and after that? IDE is something like VSCode or Jetbrains, a specific editor with bells and whistles to write code more efficiently actually, yeah, your code would be handy. Please share it in a codeblock, you can start one with ```php and end it with ```, each on their own like
ItsAmjed
ItsAmjedOP•15mo ago
if ($_SERVER['REQUEST_METHOD'] === "POST") {
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$email = $_POST['email'];

try {

require_once 'dbh.inc.php';
require_once 'signup_model.inc.php';
require_once 'signup_contr.inc.php';

// ERROR HANDLER

$error = [];

if (is_input_empty($username, $pwd, $email)) {
$error["empty_inpute"] = "Fill in all Fields";
}
if (if_email_invalid($email)) {
$error["invalid_email"] = "invalid email used";
}
if (is_username_taken($pdo, $username)) {
$error["username_taken"] = "username already taken";
}
if (is_email_registred($pdo, $email)) {
$error["email_used"] = "Email alredy registred";
}
require_once '<config_session.inc.php';
if ($error) {
$_SESSION["error_signup"] = $errors;
header("location :./index.php");
die();
}
} catch (PDOException $e) {
die(" Connection Failde:" . $e->getMessage());
}
} else {
header("location :./index.php");
die();
}
if ($_SERVER['REQUEST_METHOD'] === "POST") {
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$email = $_POST['email'];

try {

require_once 'dbh.inc.php';
require_once 'signup_model.inc.php';
require_once 'signup_contr.inc.php';

// ERROR HANDLER

$error = [];

if (is_input_empty($username, $pwd, $email)) {
$error["empty_inpute"] = "Fill in all Fields";
}
if (if_email_invalid($email)) {
$error["invalid_email"] = "invalid email used";
}
if (is_username_taken($pdo, $username)) {
$error["username_taken"] = "username already taken";
}
if (is_email_registred($pdo, $email)) {
$error["email_used"] = "Email alredy registred";
}
require_once '<config_session.inc.php';
if ($error) {
$_SESSION["error_signup"] = $errors;
header("location :./index.php");
die();
}
} catch (PDOException $e) {
die(" Connection Failde:" . $e->getMessage());
}
} else {
header("location :./index.php");
die();
}
this one for connection with db
php <?php
ini_set('session.use_only_cookies', 1);
ini_set('session.use_strict_mode', 1);

session_set_cookie_params([
'lifetime' => 1800,
'domain' => 'localhost',
'path' => '/',
'secure' => true,
'httponly' => true
]);

session_start();

if (!isset($_SESSION["last_regeneration"])) {
regenerate_session_id();
} else {
$interval = 60 * 30;
if (time() - $_SESSION["last_regeneration"] >= $interval) {
regenerate_session_id();
}
}
function regenerate_session_id()
{
session_regenerate_id();
$_SESSION["last_regeneration"] = time();
}
php <?php
ini_set('session.use_only_cookies', 1);
ini_set('session.use_strict_mode', 1);

session_set_cookie_params([
'lifetime' => 1800,
'domain' => 'localhost',
'path' => '/',
'secure' => true,
'httponly' => true
]);

session_start();

if (!isset($_SESSION["last_regeneration"])) {
regenerate_session_id();
} else {
$interval = 60 * 30;
if (time() - $_SESSION["last_regeneration"] >= $interval) {
regenerate_session_id();
}
}
function regenerate_session_id()
{
session_regenerate_id();
$_SESSION["last_regeneration"] = time();
}
Jochem
Jochem•15mo ago
Change that last line to thi:
header("Location: ./index.php");
header("Location: ./index.php");
the formatting of that string is very important
ItsAmjed
ItsAmjedOP•15mo ago
i put ( ./) cz its is another file wait let me show the rest of codes
php <?php
$host = 'localhost';
$dbname ='loginsystem';
$dbusername = 'root';
$dbpassword='';

try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname" , $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch ( PDOException $e) {
die(" Connection Failde:" .$e->getMessage());
}
php <?php
$host = 'localhost';
$dbname ='loginsystem';
$dbusername = 'root';
$dbpassword='';

try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname" , $dbusername, $dbpassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch ( PDOException $e) {
die(" Connection Failde:" .$e->getMessage());
}
Jochem
Jochem•15mo ago
did changing that line work?
ItsAmjed
ItsAmjedOP•15mo ago
nah
Jochem
Jochem•15mo ago
and without the .?
header("Location: /index.php");
header("Location: /index.php");
or even without the /
header("Location: index.php");
header("Location: index.php");
ItsAmjed
ItsAmjedOP•15mo ago
it worked '-' without .
Jochem
Jochem•15mo ago
yeah, I thought . wasn't allowed in Location headers, but second guessed myself
ItsAmjed
ItsAmjedOP•15mo ago
that all my files
No description
ItsAmjed
ItsAmjedOP•15mo ago
they are sepreted from each other that why i put .
Jochem
Jochem•15mo ago
that's not quite how the Location header works I assume you're including signup.inc.php from index.php? The browser and even the webserver will only see index.php, and that's who you're talking to with header().
ItsAmjed
ItsAmjedOP•15mo ago
oh thnx alot men i rly appreciate ur help am crying cz i spent like 3 days searching XD
Jochem
Jochem•15mo ago
glad to help! Errors can be annoying and cryptic sometimes, and there's a lot of background knowledge that you build up over time to help figure out what the problem is, it takes time 🙂 Feel free to ask sooner though, the channel's always here and if you solve your issue yourself before anyone answers, you can answer the question yourself and someone else might find the answer to their problem!
ItsAmjed
ItsAmjedOP•15mo ago
alright man thnx again @Jochem bro the same sht happen again the error back x( am gonna quite ik
Jochem
Jochem•15mo ago
what is the error in your log file this time?
ItsAmjed
ItsAmjedOP•15mo ago
same one as bfr
Jochem
Jochem•15mo ago
is there another header call in a different file with the same problem?
ItsAmjed
ItsAmjedOP•15mo ago
yeah there is but i write them as u said
Jochem
Jochem•15mo ago
the error is exactly the same in the log file? you're sure it isn't the error from an earlier request?
ItsAmjed
ItsAmjedOP•15mo ago
nah am sure its the same
[Sat Oct 21 14:37:19.797528 2023] [http:error] [pid 13952:tid 1828] [client ::1:55871] AH02429: Response header name 'location ' contains invalid characters, aborting request, referer: http://localhost/loginsystem/
[Sat Oct 21 14:37:19.797528 2023] [http:error] [pid 13952:tid 1828] [client ::1:55871] AH02429: Response header name 'location ' contains invalid characters, aborting request, referer: http://localhost/loginsystem/
Jochem
Jochem•15mo ago
try searching all your code files for 'location ' with the space, you mus've missed one somewhere
ItsAmjed
ItsAmjedOP•15mo ago
php creat_user($pdo, $username, $email, $pwd);
header("location :/index.php?signup=success");
php creat_user($pdo, $username, $email, $pwd);
header("location :/index.php?signup=success");
i only add this
Jochem
Jochem•15mo ago
That should be fine, as long as you change it to Location: /ind... location isn't the same as Location and the header you want is Location
ItsAmjed
ItsAmjedOP•15mo ago
even tho if am gonna try my error system this mssg appear in am face i tried everything XD with L or l i rewrite the code like 5 time am watching tutorial and am doing the same thing but idk why this happened to me only he writed the header location with ../ and worked for him fine
Jochem
Jochem•15mo ago
You removed the space between location and : and added one after the :?
ItsAmjed
ItsAmjedOP•15mo ago
yeah i removed it worked once and i got the log in user info in ma db but it stopped after
Jochem
Jochem•15mo ago
is it still printing fresh versions of the error to the log? If not, it might be a caching issue
ItsAmjed
ItsAmjedOP•15mo ago
i got another one
[Sat Oct 21 14:50:42.138041 2023] [php:error] [pid 13952:tid 1812] [client ::1:55933] script 'D:/xampp/htdocs/index.php' not found or unable to stat, referer: http://localhost/loginsystem/
[Sat Oct 21 14:50:42.138041 2023] [php:error] [pid 13952:tid 1812] [client ::1:55933] script 'D:/xampp/htdocs/index.php' not found or unable to stat, referer: http://localhost/loginsystem/
this one appear just now the requested url is not found in this server
Jochem
Jochem•15mo ago
try removing the / then, so header('Location: index.php?signup=success');
ItsAmjed
ItsAmjedOP•15mo ago
same error 😦 the new one this time
Jochem
Jochem•15mo ago
how are you refreshing the page?
ItsAmjed
ItsAmjedOP•15mo ago
old way am not pressing f5 i save everything in mt VS and refresh the webpage its the 404 error
Jochem
Jochem•15mo ago
right, so if you change that location, you'll have to resubmit the form instead of just refreshing the 404 page
ItsAmjed
ItsAmjedOP•15mo ago
i think i solved now let me double check everything is work well now uuuf i rewrited me location header with ../ and i checked for pervious codes and found that that some codes have < now i only need my css to appear my error in my page
Jochem
Jochem•15mo ago
cool, nice that it's solved 🙂
ItsAmjed
ItsAmjedOP•15mo ago
oh man i was cursing the day i decided to learn web dev LOL
Want results from more Discord servers?
Add your server