使用HTML的PHP​​会话 [英] PHP sessions with HTML

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

问题描述

我有一个使用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屋!

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