php 5.4升级后,电子邮件联系表格无效

时间:2014-09-18 11:57:15

标签: php contact-form

直到大约一周前,我网站上的联系表格还不错。我的主机上的PHP升级到5.4,我现在收到以下错误。

致命错误:在第3行的/homepages/17/d182268414/htdocs/contact_us.php中调用未定义的函数session_is_registered()

我没有为网站页面编写代码,并不熟悉php。如果有一种简单的方法可以让它再次运作,请告诉我。

这是php代码 -

<?
session_start();
if (!session_is_registered('enquiry_form'))
{
    session_register("enquiry_form");
    $_SESSION['title']="";
    $_SESSION['contact_name']="";
    $_SESSION['email']="";
    $_SESSION['telephone']="";
    $_SESSION['subject']="";
    $_SESSION['enquiry']="";
    $_SESSION['address1']="";
    $_SESSION['address2']="";
    $_SESSION['town']="";
    $_SESSION['county']="";
    $_SESSION['postcode']="";
    $_SESSION['country']="";
    $_SESSION['marbleCat']="unchecked";
    $_SESSION['contempCat']="unchecked";
    $_SESSION['stoneCat']="unchecked";
    $_SESSION['traditCat']="unchecked";
}
if(isset($contact)){$_SESSION['subject']=$contact;}
?>

3 个答案:

答案 0 :(得分:0)

在PHP 5.4中删除了函数session_register,session_is_registered

您需要像这样重新组织代码:

session_start();
if (empty($_SESSION['enquiry_form']))
{
    $_SESSION['enquiry_form'] = 1;
    $_SESSION['title']="";
    $_SESSION['contact_name']="";
    $_SESSION['email']="";
    $_SESSION['telephone']="";
    $_SESSION['subject']="";
    $_SESSION['enquiry']="";
    $_SESSION['address1']="";
    $_SESSION['address2']="";
    $_SESSION['town']="";
    $_SESSION['county']="";
    $_SESSION['postcode']="";
    $_SESSION['country']="";
    $_SESSION['marbleCat']="unchecked";
    $_SESSION['contempCat']="unchecked";
    $_SESSION['stoneCat']="unchecked";
    $_SESSION['traditCat']="unchecked";
}
if(isset($contact)){$_SESSION['subject']=$contact;}
?>

答案 1 :(得分:0)

session_is_registered和session_register函数已从php 5.4中删除

使用isset($ _ SESSION [“enquiry_form”])而不是

<?php
session_start();
if(!isset($_SESSION["enquiry_form"]) ){
    $_SESSION["enquiry_form"] = //Value;
    $_SESSION['title']="";
    $_SESSION['contact_name']="";
    $_SESSION['email']="";
    $_SESSION['telephone']="";
    $_SESSION['subject']="";
    $_SESSION['enquiry']="";
    $_SESSION['address1']="";
    $_SESSION['address2']="";
    $_SESSION['town']="";
    $_SESSION['county']="";
    $_SESSION['postcode']="";
    $_SESSION['country']="";
    $_SESSION['marbleCat']="unchecked";
    $_SESSION['contempCat']="unchecked";
    $_SESSION['stoneCat']="unchecked";
    $_SESSION['traditCat']="unchecked";
}
if(isset($contact)){$_SESSION['subject']=$contact;}
?>

您还应该使用<?php

<? insteand

答案 2 :(得分:0)

更改您的代码: -

if (!session_is_registered('enquiry_form'))
{
    session_register("enquiry_form");

if (!isset($_SESSION['enquiry_form']))
{
    $_SESSION["enquiry_form"]= 'myvalue';

session_register() has been removed from php 5.4

您可以使用$_SESSION[]

用于在会话中设置变量: -

session_start()
$_SESSION['myvar'] = $myvar;

从会话中获取变量: -

$myvar = $_SESSION['myvar'];

用于检查会话变量: -

if( isset($_SESSION["myvar"]) ){