简体   繁体   English

如何启动用于登录php-mysql的会话?

[英]how to start session for login php-mysql?

im trying to figure out whats wrong with my codes. 我试图找出我的代码有什么问题。 everytime I try to run this. 每次我尝试运行此程序。 theres an error Fatal error: Function name must be a string. 出现错误致命错误:函数名称必须是字符串。 could someone help me. 有人可以帮助我。 thanks 谢谢

 <?php

$username = "root";
$password = "password";
$hostname = "localhost";

$dbhandle = mysql_connect($hostname, $username, $password) or die("Could not connect to database");
$selected = mysql_select_db("ramon_pascual", $dbhandle);

$myusername = $_POST['user'];
$mypassword = $_POST['pass'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);

session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")


$query = "SELECT * FROM ramon_account WHERE username='$myusername'  and password='$mypassword'";
$result = mysql_query($query);
$count = mysql_num_rows($result);

mysql_close();

if ($count==1) 
{
    $_SESSION($myusername);
    #$_SESSION['login_user'] = $myusername;
    #$seconds = 120 + time(); 
    #setcookie(loggedin, date("F jS - g:i a"), $seconds);
    header("location:admin.php");

}
else
{
    echo 'Incorrect Username or Password';
}


?>

there's a problem in this line in which I cant figure out why 这行有一个问题,我无法弄清楚为什么

$_SESSION($myusername);

You use session as a function on line $_SESSION($myusername) . 您可以在$_SESSION($myusername)$_SESSION($myusername) session用作函数。

It's an array, so the correct syntax is: 这是一个数组,所以正确的语法是:

$_SESSION['username'] = $myusername;

You need to change your braces, and you are handling an array. 您需要更改花括号,并且正在处理数组。 So: 所以:

$_SESSION($myusername);

should be 应该

$_SESSION['user'] = $myusername;

Also, make sure to start session with 另外,请确保以

session_start();

at the very top of your file! 在文件的最上方!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM