Unable to process this request via localhost at this time. HTTP ERROR
Taijin
Posted messages
55
Status
Membre
-
jordane45 Posted messages 30426 Registration date Status Modérateur Last intervention -
jordane45 Posted messages 30426 Registration date Status Modérateur Last intervention -
Hello, yesterday I created a registration and login system on my website with PHP pages (I am using MAMP). I created a registration page and a login page, and when I click on them, everything works fine, both pages open correctly. However, when I try to log in or register, it shows a page with "Unable to handle this request via localhost at this time. HTTP ERROR"
Thank you very much and have a good evening.
Thank you very much and have a good evening.
5 réponses
Hello,
A 500 error... it's a server error.
This therefore suggests an error in your php code...
And in order to help you... you need to show it to us..
NOTE: To post your code on the forum, you will need to use CODE TAGS.
Explanations, to be read IN FULL, are available here:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
--
.
Best regards,
Jordane
A 500 error... it's a server error.
This therefore suggests an error in your php code...
And in order to help you... you need to show it to us..
NOTE: To post your code on the forum, you will need to use CODE TAGS.
Explanations, to be read IN FULL, are available here:
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
--
.
Best regards,
Jordane
Wouldn't it be easier if I send screenshots of my pages since I have 7 pages for my sign-up and login system?
D'accord, excusez-moi, voici le code de ma page login.php
<?php session_start(); require_once 'config.php'; if(isset($_POST['email']) && isset($_POST['password'])) { $email = htmlspecialchars($_POST['email']); $password = htmlspecialchars($_POST['password']); $check = bdd->prepare('SELECT username, email, password FROM users WHERE email=?'); $check->execute(array($email)); $data = $check->fetch(); $row = $check->rowCount(); if($row ==1) { if(filter_var($email, FILTER_VALIDATE_EMAIL)) { $password = hash('sha256', $password); if($data['password']===$password) { $_SESSION['user'] = $data['username']; header('Location:landing.php'); }else header('Location:index.php?login_err=password'); }else header('Location:index.php?login_err=email'); }else header('Location:index.php?login_err=already'); }else header('Location:index.php'); ?>
htmlspecialchars should only be used for display purposes.. never for processing data to be stored in the database
to hash the password, you should now use the functions password_hash($password, $algo) (and password_verify($password, $hash) to verify that it's correct)
rowCount(); should not be used for "select" type queries (see the PHP documentation on this if needed)
You forgot a $ before the variable name bdd in your prepare
Corrected code:
.
Best regards,
Jordane
to hash the password, you should now use the functions password_hash($password, $algo) (and password_verify($password, $hash) to verify that it's correct)
rowCount(); should not be used for "select" type queries (see the PHP documentation on this if needed)
You forgot a $ before the variable name bdd in your prepare
Corrected code:
<?php //Start the sessions session_start(); //Display PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once 'config.php'; //Clean retrieval of variables before using them $email = !empty($_POST['email']) ? $_POST['email'] : NULL; $password = !empty($_POST['password']) ? $_POST['password'] : NULL; if ($email && $password) { try { $check = $bdd->prepare('SELECT pseudo, email, password FROM utilisateur WHERE email=?'); $check->execute(array($email)); $data = $check->fetch(); } catch (Exception $e) { echo "Error in the query: " . $e->getMessage(); } if (!empty($data)) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { if (password_verify($password, $data['password'])) { $_SESSION['user'] = $data['pseudo']; header('Location:landing.php'); exit; //always put an exit after a redirect } else { header('Location:index.php?login_err=password'); exit; //always put an exit after a redirect } } else { header('Location:index.php?login_err=email'); exit; //always put an exit after a redirect } } else { header('Location:index.php?login_err=already'); exit; //always put an exit after a redirect } } else { header('Location:index.php'); exit; //always put an exit after a redirect } ?> .
Best regards,
Jordane
Hello, thank you very much for your response. I have applied the new code, but I still get the same message...
I also have a second question: I have "htmlspecialchars" in almost all my PHP pages. I understood that it was normal in my two pages for display, but I have two additional pages where I have htmlspecialchars
Do you want me to send you the entire folder with the code, by email for example?
Thank you in advance
Have a good evening!
I also have a second question: I have "htmlspecialchars" in almost all my PHP pages. I understood that it was normal in my two pages for display, but I have two additional pages where I have htmlspecialchars
Do you want me to send you the entire folder with the code, by email for example?
Thank you in advance
Have a good evening!
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
P.S.: I hope you don’t have spaces in the dbname or other variables... and that these are just dummy data you put just to post on the forum....
I have made the changes based on what you sent me, but it still doesn't work
And no, what I sent you is indeed my actual code
And no, what I sent you is indeed my actual code
<?php try { $bdd = new PDO ('mysql:host=localhost;dbname=site internet;charset=utf8', "LOGIN", "PASS"); $bdd -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }catch(Exception $e) { die('Erreur' .$e->getMessage()); } ?>
We'll go step by step.
Could you, initially, keep only the lines in your connexion.php file
If it displays correctly, then the issue lies with something afterward...
By the way, what are you using to test your pages?
Which software?
What version of PHP?
--
.
Best regards,
Jordane
Could you, initially, keep only the lines in your connexion.php file
<?php //Start the sessions session_start(); //Display PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once 'config.php'; echo " OK"; If it displays correctly, then the issue lies with something afterward...
By the way, what are you using to test your pages?
Which software?
What version of PHP?
--
.
Best regards,
Jordane
I have kept the code you provided, the page displays correctly, but when I click on login, it shows me the same message
I am using Sublime Text 3 and I open my pages in Google Chrome if that was your question.
<?php //Start the sessions session_start(); //Display PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once 'config.php'; echo " OK"; ?> I am using Sublime Text 3 and I open my pages in Google Chrome if that was your question.
It's normal because this page does not manage the display. I will try to explain how it works again, as I had trouble doing so earlier.
The homepage of the site is called "site.html", which contains a link to the "inscription.php" and "index.php" pages.
When I click on the link leading to "inscription.php", a page opens where I need to enter a name, email, and password.
When I click on "sign up," it takes me to my "inscription_traitement.php" page, and that's when the message appears.
When I click on "index.php" on my main page, I need to enter an email and password to log in. Then, when I click on "login," it redirects me to the "connexion.php" page, and that's when the message also appears.
I hope I have been clear in my explanation, and I apologize if I was not clear before.
Thank you very much for your patience.
The homepage of the site is called "site.html", which contains a link to the "inscription.php" and "index.php" pages.
When I click on the link leading to "inscription.php", a page opens where I need to enter a name, email, and password.
When I click on "sign up," it takes me to my "inscription_traitement.php" page, and that's when the message appears.
When I click on "index.php" on my main page, I need to enter an email and password to log in. Then, when I click on "login," it redirects me to the "connexion.php" page, and that's when the message also appears.
I hope I have been clear in my explanation, and I apologize if I was not clear before.
Thank you very much for your patience.
When I get the error message, I either have the URL "http://localhost/connexion.php" if I want to connect, or I have "http://localhost/inscription_traitement.php" if I want to register.
Here is my code for the inscription_traitement page.
Here is my index.php page.
My connexion.php page only contains what you provided me earlier.
And here is my inscription.php page.
Here is my code for the inscription_traitement page.
<?php require_once 'config.php'; if(isset($_POST['pseudo']) && isset($_POST['email']) && isset($_POST['password']) && isset($_POST['password_retype'])) { $pesudo = htmlspecialchars($_POST['pseudo']); $email = htmlspecialchars($_POST['email']); $password = htmlspecialchars($_POST['password']); $password_retype = htmlspecialchars($_POST['password_retype']); $check = bdd->prepare('SELECT pseudo, email, password FROM utilisateur WHERE email=?'); $check->execute(array($email)); $data = $check->fetch(); $row = $check->rowCount(); if($row == 0) { if(strlen($pseudo) <= 100) { if (strlen($email) <= 100) { if(filter_var($email, FILTER_VALIDATE_EMAIL)) { if($password == $password_retype) { $password = hash('sha256', $password); $ip = $_SERVER['REMOTE_ADDR']; $insert = $bdd->prepare('INSERT INTO utilisateur(pseudo, email, password, ip) VALUES(:pseudo, :email, :password, :ip)'); $insert->execute(array( 'pseudo' => $pseudo, 'email' => $email, 'password' => $password, 'ip' => $ip )); header('Location:http://localhost/inscription.php?reg_err=success'); }else header('Location: inscription.php?reg_err=password'); }else header('Location: inscription.php?reg_err=email'); }else header('Location: inscription.php?reg_err=email_length'); }else header('Location: inscription.php?reg_err=pseudo_length'); }else header('Location: inscription.php?reg_err=already'); } ?> Here is my index.php page.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="author" content="NoS1gnal"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <title>Login</title> </head> <body> <div class="login-form"> <?php if(isset($_GET['login_err'])) { $err = htmlspecialchars($_GET['login_err']); switch ($err) { case 'password': ?> <div class="alert alert-danger"> <strong>Error</strong> incorrect password </div> <?php break; case 'email': ?> <div class="alert alert-danger"> <strong>Error</strong> incorrect email </div> <?php break; case 'already': ?> <div class="alert alert-danger"> <strong>Error</strong> account does not exist </div> <?php break; } } ?> <form action="connexion.php" method="post"> <h2 class="text-center">Login</h2> <div class="form-group"> <input type="email" name="email" class="form-control" placeholder="Email" required="required" autocomplete="off"> </div> <div class="form-group"> <input type="password" name="password" class="form-control" placeholder="Password" required="required" autocomplete="off"> </div> <div class="form-group"> <button type="submit" class="btn btn-primary btn-block">Login</button> </div> </form> <p class="text-center"><a href="inscription.php">Register</a></p> </div> <style> .login-form { width: 340px; margin: 50px auto; } .login-form form { margin-bottom: 15px; background: #f7f7f7; box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); padding: 30px; } .login-form h2 { margin: 0 0 15px; } .form-control, .btn { min-height: 38px; border-radius: 2px; } .btn { font-size: 15px; font-weight: bold; } </style> </body> </html> My connexion.php page only contains what you provided me earlier.
<?php //Start sessions session_start(); //Display PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once 'config.php'; echo " OK"; ?> And here is my inscription.php page.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="author" content="NoS1gnal"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> <title>Registration</title> </head> <body> <div class="login-form"> <?php if(isset($_GET['reg_err'])) { $err = htmlspecialchars($_GET['reg_err']); switch($err) { case 'success' : ?> <div class="alert alert-success"> <strong>Success</strong> registration successful! </div> <?php break; case 'password' : ?> <div class="alert alert-danger"> <strong>Error</strong> passwords do not match </div> <?php break; case 'email' : ?> <div class="alert alert-danger"> <strong>Error</strong> invalid email </div> <?php break; case 'email_length' : ?> <div class="alert alert-danger"> <strong>Error</strong> email too long </div> <?php break; case 'pseudo_length' : ?> <div class="alert alert-danger"> <strong>Error</strong> username too long </div> <?php break; case 'already' : ?> <div class="alert alert-danger"> <strong>Error</strong> account already exists </div> <?php } } ?> <form action="inscription_traitement.php" method="post"> <h2 class="text-center">Registration</h2> <div class="form-group"> <input type="text" name="pseudo" class="form-control" placeholder="Username" required="required" autocomplete="off"> </div> <div class="form-group"> <input type="email" name="email" class="form-control" placeholder="Email" required="required" autocomplete="off"> </div> <div class="form-group"> <input type="password" name="password" class="form-control" placeholder="Password" required="required" autocomplete="off"> </div> <div class="form-group"> <input type="password" name="password_retype" class="form-control" placeholder="Re-enter password" required="required" autocomplete="off"> </div> <div class="form-group"> <button type="submit" class="btn btn-primary btn-block">Register</button> </div> </form> </div> <style> .login-form { width: 340px; margin: 50px auto; } .login-form form { margin-bottom: 15px; background: #f7f7f7; box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); padding: 30px; } .login-form h2 { margin: 0 0 15px; } .form-control, .btn { min-height: 38px; border-radius: 2px; } .btn { font-size: 15px; font-weight: bold; } </style> </body> </html>
Check that your files are properly encoded in UTF-8 without BOM
See chapter 1 of the following link
https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8
Don't hesitate to create a new file to replace the existing one to ensure that you are doing it correctly
Then retry by commenting out the require line...
And let me know if you still have the 500 error...
See chapter 1 of the following link
https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8
Don't hesitate to create a new file to replace the existing one to ensure that you are doing it correctly
Then retry by commenting out the require line...
And let me know if you still have the 500 error...
I have successfully recreated a new page and checked that I was in UTF-8, however it still does not work
Here is my page connexion.php
Here is my page connexion.php
<?php //Starting sessions session_start(); //Displaying PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); require_once 'config.php'; echo " OK"; ?>
I asked you to test it without the require.
Did you do it?
Basically, in your connexion.php file, you only keep:
Then try to access this page and let us know if you're still getting a 500 error...
If so... it means there's a configuration issue on your server...
Haven't you set up a .htaccess file??
Could you try moving your project to a subfolder of your web directory? Because I have the impression that you placed your files directly in the htdocs (or www depending on the software used to emulate the web server)...
Did you do it?
Basically, in your connexion.php file, you only keep:
<?php //Start sessions session_start(); //Display PHP errors error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); // require_once 'config.php'; echo " OK"; ?> Then try to access this page and let us know if you're still getting a 500 error...
If so... it means there's a configuration issue on your server...
Haven't you set up a .htaccess file??
Could you try moving your project to a subfolder of your web directory? Because I have the impression that you placed your files directly in the htdocs (or www depending on the software used to emulate the web server)...