使用HTML的PHP会话 [英] PHP sessions with HTML
问题描述
我有一个使用PHP和HTML页面的网站,我想创建一个存储登录页面的用户名的会话。但是登录页面是php,接下来的页面是html。
这是一个问题,还是我可以在html页面添加一个小小的声明php
<?PHP session_start();
$ _session ['loginid'] = $ _ post ['username'];
?>
或者我做错了吗?
这是我第一次使用会话,他们混淆了我一点。
感谢您的任何帮助。
如果您有权访问您的apache配置或简单的.htaccess文件,您可以告诉Apache处理.html文件中的php代码。您可以通过在网站的文档根目录(可能是public_html /)上创建一个 .htaccess 文件(记住。(点)作为该文件名中的第一个字符)并将其放入该文件中:
#将此项添加到public_html / .htaccess文件
AddHandler应用程序/ x-httpd-php .html
AddHandler应用程序/ x-httpd-php .htm
您应该可以重新加载html页面你的PHP代码(来自迈克尔马修斯的答案)将运行得很好。
I have a website which uses PHP and HTML pages, I want to create a session which stores a username from the login page. But the login pages are php and the next pages are html.
Is this a problem or can I just add a small statement of php into the html page saying
<?PHP session_start();
$_session['loginid']=$_post['username'];
?>
Or am I doing it wrong?
This is the first time i've used sessions and they confuse me a little.
thanks for any help.
If you have access to your apache configuration, or a simple .htaccess file, you can tell Apache to handle php code inside of an .html file. You can do this by creating an .htaccess file (remember the . (dot) as the first character in that filename) on the document root of the site (probably public_html/) and putting this into it:
# Add this to public_html/.htaccess file
AddHandler application/x-httpd-php .html
AddHandler application/x-httpd-php .htm
You should be able to reload the html page and your PHP code (from Michael Matthews answer) will run great.
这篇关于使用HTML的PHP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!