PHP $ _SESSION问题 [英] PHP $_SESSION problem

查看:122
本文介绍了PHP $ _SESSION问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的网站创建了登录页面。我得到一个错误在第30行与$ _SESSION ['username'] = $ username;在这里, - 解析错误:语法错误,意外的T_VARIABLE

I'm making a login page for my website. It is also done [done in the sense that it will not, not in the sense that it is secure.] am getting an error on line 30 with "$_SESSION['username']=$username;" - "Parse error: syntax error, unexpected T_VARIABLE"

所有数据库信息称为db12345,以隐藏凭证。此外,此登录页面的唯一一点是使用名为members的数据库表将用户登录到站点,并导致用户到包含一些链接的页面。

All database information is be called "db12345" to hide the credentials. Also, the only point to this login page is to log the user into the site using the database table called "members" and lead to the user to a page with some links.

<?php

session_start();

$username = $_POST ['username'];
$password = $_POST ['password'];

if ($username&&$password)
{
$connect = mysql_connect("localhost", "db12345", "db12345") or die("could not connect to mysql"); 
mysql_select_db("db12345") or die("could not connect to db");
}

$query = mysql_query("SELECT * FROM members WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows!=0)
{

while  ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}

if ($username==$dbusername&&$password==$dbpassword)
{
echo ("you're in, click <a href="#">here</a> to enter your profile");
$_SESSION['username']=$username; 
}
else
{
echo ("please enter your username and password");
}

?>

谢谢。我确定这只是一个很简单的东西我搞砸了!

Thank you. I'm sure this is just something very simple I messed up!

推荐答案

上面的行是问题。您在字符串中使用双引号,使用双引号作为被包围的分隔符。使用单引号来换行(和转义单引号),或使用双引号(和转义双引号)。例如

Line above it is the issue. You're using double quotes within a string that is using double-quotes as the surrounded delimiter. Either use single quotes to wrap (and escape the single quote within), or use double quotes (and escape the doubles within). e.g.

// double quotes with escaped double quotes:
echo ("you're in, click <a href=\"#\">here</a> to enter your profile");

// single quotes, with escaped single quote
echo ('you\'re in, click <a href="#">here</a> to enter your profile');

请参阅 php strings 的其他示例。

这篇关于PHP $ _SESSION问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆