为什么PHP对象操作符在浏览器中被视为关闭标签? [英] Why is PHP Object Operator being viewed as closing tag in browser?

查看:86
本文介绍了为什么PHP对象操作符在浏览器中被视为关闭标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP来检查HTML页面顶部的$ _SESSION变量。这里是我的代码:

 <?php require('sessions.class.php'); 
$ session = new session();
$ session-> start_session('_ s',false);

if(!isset($ _ SESSION('session_id'))){
header(location:'login.html');
}
?>

<!DOCTYPE html>

一切似乎一直运行到Object Operator( - > )。这就像服务器将其视为PHP结束标签。 - > 后面的文字在网页顶部回显。



这与所提问题类似这里:



为什么-php-tag-is-closing-on-user



但OP没有详细介绍解决方案。



浏览器= Mozilla



任何帮助将不胜感激。谢谢!

解决方案

这个问题可能是您试图在不可能的html文档中运行PHP代码。 <的PHP开始标记被认为是html标记的开始,因此第一个>之后的代码以文本形式输出,因为它被解释为关闭html标记。



如果您想使用PHP,请将其设为.php文件并回显html。更好的是,您希望尽可能将您的逻辑(PHPcode)和标记(html)分开放在单独的文件中。

搜索分离PHP和html
为了让你开始


I am using PHP to check for $_SESSION variables at the top of an HTML page. Here is my code:

<?php require('sessions.class.php');
 $session= new session();
 $session->start_session('_s',false);

 if (!isset($_SESSION('session_id'))){
    header(location:'login.html');
  }
 ?>

<!DOCTYPE html>

Everything seems to work until the Object Operator (->) is reached. It's like the server views this as the PHP closing tag. The text after -> is echoed at the top of the webpage.

This is similar to the question asked here:

why-php-tag-is-closing-on-user

But the OP did not go into the solution with much detail.

Browser= Mozilla

Any help would be appreciated. Thanks!

解决方案

The problem is probably that you are trying to run PHP code in an html document which is not possible. The < of the PHP opening tag is recognised as the start of an html tag and therefore the code after the first > is output as text, since it is interpreted as the closing of the html tag.

If you want to use PHP, make it a .php file and echo the html. Better yet you want to separate your logic (PHPcode) and markup (html) in separate files as much as possible.

Search for 'separating PHP and html' To get you started

这篇关于为什么PHP对象操作符在浏览器中被视为关闭标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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