语法错误意外'?' 在当地工作[关闭]
问题描述:
i have this code in the top of my index.php. And it works perfect when i run it locally with mamp. But when i go live with the page and upload it to the hosting service and launch the website i get this error in the log. And the site does not load.
PHP Parse error: syntax error, unexpected '?' in /home/*****/*****.*****.**/index.php on line 3
<?php
session_start();
$AccountsucessRegister = $_SESSION['Accountsucess'] ?? '';
$AccountfailRegister = $_SESSION['Accountfail'] ?? '';
unset($_SESSION['Accountsucess']);
unset($_SESSION['Accountfail']);
?>
<?php if ($AccountsucessRegister !== ''): ?>
<?php echo "<script>alert('$AccountsucessRegister');</script>" ?>
<?php endif; ?>
<?php if ($AccountfailRegister !== ''): ?>
<?php echo "<script>alert('$AccountfailRegister');</script>" ?>
<?php endif; ?>
我的代码位于index.php的顶部。 当我在mamp本地运行它时,它的工作非常完美。 但是,当我上传页面并将其上传到托管服务并启动网站时,我在日志中收到此错误。 并且该网站无法加载。 p>
PHP解析错误:语法错误,意外'?' 在第3行的 /home/*****/*****.*****.**/index.php p> blockquote>
&lt;?php session_start(); $ AccountsucessRegister = $ _SESSION ['Accountsucess'] ?? ''; $ AccountfailRegister = $ _SESSION ['Accountfail'] ?? ''; unset($ _ SESSION ['Accountsucess']); unset($ _ SESSION ['Accountfail']); ?&gt; &lt;?php if($ AccountsucessRegister!==''):? &gt; &lt;?php echo“&lt; script&gt; alert('$ AccountsucessRegister');&lt; / script&gt;” ?&gt; &lt;?php endif; ?&gt; &lt;?php if($ AccountfailRegister!==''):?&gt; &lt;?php echo“&lt; script&gt; alert('$ AccountfailRegister');&lt; / script&gt;” ?&gt; &lt;?php endif; ?&gt; code> pre> div>
答
Maybe you have on local php7+ version and at your provider not.
Among provider have .ini file option to change the php version on shared hosting but if not the error comes from
$AccountsucessRegister = $_SESSION['Accountsucess'] ?? '';
must be
$AccountsucessRegister = isset($_SESSION['Accountsucess']) ? $_SESSION['Accountsucess'] : '';