how can I go back to calling page using location.replace?

I still haven't solved my last problem, which codes are

PHP Code:
``` if (isExistingShowtime(\$db)) { ?>     <script language="javascript">      <!--          alert("this showtime has been already in my schedule");         location.replace=("<?php echo \$_SERVER['HTTP_REFERER']; ?>");              -->      </script>  <?php  } ```
I've found that if I gave definitive url to replace something like
location.replace=("index.php");

it goes to the index page after showing alert.
But I absolutely need \$_SERVER['HTTP_REFERER'] as this one is called from various page.
What's wrong with my replace code?

Thanks,