开发者

PHP Syntax issue with headers

Can't seem to get it right with the syntax:

<?php 
if isset $_POST['tutorial'] {
    header('Location: /phonebooks?tutorial=1b');
} else {
    header('Location: /phonebooks?phonebook_created开发者_开发知识库=1');
};
?>

What am I doing wrong??


Ok, first off, you need to use parenthesis. Multiple parenthesis.

The first set need to go around the contents of the if construct:

if ( ... ) {

The second set need to go around the isset() function call:

isset($_POST['tutorial'])

So that line becomes:

if (isset($_POST['tutorial'])) {

You also have another problem. Don't use location headers with relative urls. It's against the HTTP specification. Always use absolute URLs, otherwise you may break some webservers (I know IIS hates it), or browsers...


You're missing brackets around your if condition and around $_POST['tutorial'], which is an argument to isset. It should be:

<?php 
if (isset($_POST['tutorial']))
{
  header('Location: /phonebooks?tutorial=1b');
}
else
{
  header('Location: /phonebooks?phonebook_created=1');
}
?>

As pointed out in the comments, an absolute URL is required for a Location header as well (so instead of /phonebooks?tutorial=1b, you'd need to specify http(s)://yourdomain.com/phonebooks?tutorial=1b).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜