标题位置php

I've made this block of code:

$tag = $_GET['tag'];

if ($_SERVER[HTTP_REFERER'] == 'http://sitename.com/portfolio' || $_SERVER['HTTP_REFERER'] == 'sitename.com/tags/?tagname=' . $tag ) : ?>

<figure class="folio-item">
    <img src="<?php echo $mod->src; ?>" alt="">
</figure>

<?php  else : ?>
   <?php header('http://sitename.com/portfolio'); ?>
<?php endif ?>

So if the statement is true it has to make the figure, which does work. but when the statement isn't true it gives me a empty file instead of heading me to sitename.com/portfolio

how can i make this work?

the Solution:

$tag = $_GET['tag'];

if ($_SERVER[HTTP_REFERER'] == 'http://sitename.com/portfolio' ||       $_SERVER['HTTP_REFERER'] == 'sitename.com/tags/?tagname=' . $tag ) : ?>

<figure class="folio-item">
    <img src="<?php echo $mod->src; ?>" alt="">
</figure>

<?php  else : ?>
   <?php header('Location:http://sitename.com/portfolio'); ?>
<?php endif ?>

I added Location: to the header function like Brian said.

you have to tell it that you are setting a location rather than another header attribute

<?php  else : ?>
   <?php header('Location: http://sitename.com/portfolio'); exit; ?>
<?php endif ?>

the exit; statement tells it to stop executing which allows the redirect. You also need to make sure you don't spit out any html before you redirect.