2017-06-21 69 views
0

我正在使用xampp,并且我的文件位于xampp/htdocs/Project中。 我认为PHP代码出现在网站上,因为我在浏览器中调用它的方式:http://localhost:8081/login.php但我不确定这是否是问题所在。登录页面显示的是php代码和下一步

我的login.php是像现在这样的权利:http://imgur.com/a/nCpI1

的login.php代码:

<!DOCTYPE html> 
<html lang="pt-PT"> 
<head> 
    <meta charset="UTF-8"> 
    <title>LOGIN</title> 
    <link rel="stylesheet" type="text/css" href="styles/menu.css"> 
    <link rel="stylesheet" type="text/css" href="styles/homesheet.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> 
<link href="https://fonts.googleapis.com/css?family=Fira+Sans+Condensed" rel="stylesheet"> 
</head> 
<body> 

<?php 
error_reporting(E_ALL); 

session_start(); 

//Start Database 

$con = mysqli_connect("localhost","root","","loja"); 

// Check connection 
if (!$con) { 
    echo "<div>"; 
    echo "Falha ao conectar ao MySQL: " . mysqli_connect_error(); 
    echo "</div>"; 
} 
if(isset($_SESSION["name"]) && $_SESSION["name"]) 
{ 
    echo "You are already logged in, ".$_SESSION['name']."! <br> I'm Loggin you out M.R .."; 
    unset($_SESSION); 
    session_destroy(); 
    header('Location: login.php'); 
    exit; 
} 

$loggedIn = false; 

$userName = isset($_POST["name"]) ? $_POST["name"] : null; 

$userPass = isset($_POST["pass"]) ? $_POST["pass"] : null; 

if ($userName && $userPass) 
{ 
    $query = "SELECT username FROM login WHERE username = '$userName' AND password = '$userPass'"; 
    $result = mysqli_query($con, $query); 
    $row = mysqli_fetch_array($result); 

    if(!$row){ 
     echo "<div>" 
     echo "Dados invalidos."; 
     echo "</div>" 
    } 
    else { 
     $loggedIn = true; 
    } 
} 

if (!$loggedIn) 
{ 
    echo " 
      <div style='width:500px;'> 
       <h3>Login</h3> 
       <form method='post'> 
        <label>Username</label> 
        <input type='text' name='name' placeholder='Username' value='$userName'/> 
        <label>Password</label> 
        <input type='password' name='pass' placeholder='Password' value='$userPass'/> 
        <button>Login</button> 
       </form> 
      </div> 

      <footer> 
       <h4 style="text-align:right;">Copyright &copy; est.setubal.com</h4> 
      </footer> 
     "; 
} 
else{ 
    echo "<div>"; 
    echo "Iniciou a sessao como: $userName!"; 
    echo "</div>"; 
    header('Location: home.html'); 
    $_SESSION["name"] = $userName; 
} 
?> 
</body> 
</html> 

session.php文件:

<?php 
// Establishing Connection with Server by passing server_name, user_id and password as a parameter 
$connection = mysql_connect("localhost", "root", ""); 

// Selecting Database 
$db = mysql_select_db("loja", $connection); 
session_start();// Starting Session 
// Storing Session 
$user_check=$_SESSION['login_user']; 
// SQL Query To Fetch Complete Information Of User 
$ses_sql=mysql_query("select user from login where user='$user_check'",$connection); 
$row = mysql_fetch_assoc($ses_sql); 
$login_session =$row['user']; 
if(!isset($login_session)){ 
mysql_close($connection); // Closing Connection 
header('Location: main.php'); // Redirecting To Home Page 
} 
?> 

我的表 “登录” 作为用户名和密码字段在里面。我需要一个全新的眼睛,可以告诉我还需要做些什么才能使登录正常工作。

+1

您是否设置了端口8081?不要使用'mysql_ *'进行新的开发。 – chris85

+0

如果你刚刚开始使用PHP,从一些框架开始,将会得到该代码组织的肯定..例如:[CakePHP3](https://cakephp.org/)..有一个很好的博客教程做从头开始。 – fabricio

+0

我确实使用那个端口。而且我正在使用'mysql_ *',因为我正在使用旧的项目登录名。但我尝试在PDO中搜索一个登录系统,并尝试使用它们,但它们不起作用。 – fabimetabi

回答

0

看来你的PHP模块丢失

您必须包含在httpd.conf

# XAMPP settings 
Include "conf/extra/httpd-xampp.conf" 

httpd-xampp.conf默认设置位于xampp\apache\conf\extra\httpd-xampp.conf

# 
# PHP-Module setup 
# 
LoadFile "F:/xampp/php/php7ts.dll" 
LoadFile "F:/xampp/php/libpq.dll" 
LoadModule php7_module "F:/xampp/php/php7apache2_4.dll" 

<FilesMatch "\.php$"> 
    SetHandler application/x-httpd-php 
</FilesMatch> 
<FilesMatch "\.phps$"> 
    SetHandler application/x-httpd-php-source 
</FilesMatch> 

# 
# PHP-CGI setup 
# 
#<FilesMatch "\.php$"> 
# SetHandler application/x-httpd-php-cgi 
#</FilesMatch> 
#<IfModule actions_module> 
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe" 
#</IfModule> 


<IfModule php7_module> 
    PHPINIDir "F:/xampp/php" 
</IfModule> 

<IfModule mime_module> 
    AddType text/html .php .phps 
</IfModule> 

ScriptAlias /php-cgi/ "F:/xampp/php/" 
<Directory "F:/xampp/php"> 
    AllowOverride None 
    Options None 
    Require all denied 
    <Files "php-cgi.exe"> 
      Require all granted 
    </Files> 
</Directory> 

<Directory "F:/xampp/cgi-bin"> 
    <FilesMatch "\.php$"> 
     SetHandler cgi-script 
    </FilesMatch> 
    <FilesMatch "\.phps$"> 
     SetHandler None 
    </FilesMatch> 
</Directory> 
0

我猜你开始了Apache通过XAMPP服务... 您的代码看起来不错...尝试键入http://localhost/login.php不与8081 ...它可能会解决您的问题! 否则查找httpd.conf文件(xampp app config-> httpd.conf)是否搞砸了!