php - remove - strip_tags()
Index.php causa alerta vacĂa en el sitio web en vivo (1)
Así que tengo index.php tiene mi página predeterminada. Funciona bien en xampp. Así que cargué todo mi sitio a 1 y 1 (mi dominio / proveedor de alojamiento) y cuando intento ir a mi dominio recibo una alerta vacía sin mensaje y una página completamente en blanco.
Cambié el nombre del archivo a index.html y la página web cargó muy bien. Entonces sé que debe ser algo con la extensión .php o mi código arriba.
También agregué un archivo llamado .htaccess y solo contiene:
DirectoryIndex index.php
Aquí está mi código php en la parte superior de index.php (remplazo de información confidencial con * s):
<?php
//Connect to a database
$host_name = "******.db.1and1.com";
$database = "db****";
$user_name = "dbo******";
$password = "***z.0**";
$connect = mysqli_connect($host_name, $user_name, $password, $database);
// echo("nice job");
//Take the values from the html form and assign them to variables
$ID = $_POST[''name''];
$userpassword = $_POST[''password''];
//If no passsowrd entered then go straight to index.php
echo "<script type=''text/javascript''>alert($userpassword);</script>";
if ($userpassword == null) {
header("Location: http://localhost:82/index3.php");
die();
}
//Check to see if the password matches the hashes
if (md5($userpassword) === ''******************''
or md5($userpassword) === ''***********''
or md5($userpassword) === ''****************''
or md5($userpassword) === ''**************'')
{
//Add the visitor name to our list
mysqli_query($connect, "INSERT INTO `WebsiteVisitors` (`Name`) VALUES (''$ID'')") or die("Error in INSERT: ".mysqli_error($connect));
// echo "You have entered the correct password, congrats.";
// Start the session so they can access other pages
session_start();
$_SESSION[''loggedIn''] = true;
// Redirect them to rest of site
header("Location: http://localhost:82/home.php");
die();
}
else {
header("Refresh: 0; url=index2.php");
echo "<script type=''text/javascript''>alert(/"Wrong Password. Check your invitation card./");</script>";
}
?>
Dado que la solicitud $_POST
solo aparece después de enviar el formulario en su caso, solo debe ejecutar las comprobaciones de nombre de usuario y contraseña si $_POST["name"]
y $_POST["password"]
existen.
Así que proporcione una declaración if(isset($_POST[''name'']) && isset($_POST[''password'']))
antes de usar y manipular las variables $_POST
. Alson session_start()
debe dar en la parte superior de su script.
A continuación se muestra su código completo, incluido el cheque
<?php
session_start();
// session start should be at top of your script
error_reporting(E_ERROR); // reports only errors
//Connect to a database
$host_name = "******.db.1and1.com";
$database = "db****";
$user_name = "dbo******";
$password = "***z.0**";
$connect = mysqli_connect($host_name, $user_name, $password, $database);
// $_POST request comes only when form is submitted in your case. So check for $_POST[''name''] and $_POST[''password'']
if(isset($_POST[''name'']) && isset($_POST[''password'']))
{
$ID = $_POST[''name''];
$userpassword = $_POST[''password''];
//If no passsowrd entered then go straight to index.php
if ($userpassword == null)
{
echo "<script type=''text/javascript''>alert("Empty Password");</script>";
header("Location: http://localhost:82/index3.php");
die();
}
//Check to see if the password matches the hashes
if (md5($userpassword) === ''******************''
or md5($userpassword) === ''***********''
or md5($userpassword) === ''****************''
or md5($userpassword) === ''**************'')
{
//Add the visitor name to our list
mysqli_query($connect, "INSERT INTO `WebsiteVisitors` (`Name`) VALUES (''$ID'')") or die("Error in INSERT: ".mysqli_error($connect));
$_SESSION[''loggedIn''] = true;
// Redirect them to rest of site
header("Location: http://localhost:82/home.php");
die();
}
else
{
echo "<script type=''text/javascript''>alert(/"Wrong Password. Check your invitation card./");</script>";
header("Refresh: 0; url=index2.php");
}
}
?>