hasani hasani - 3 months ago 19
PHP Question

How to include php file instead of url in php redirect

Instead of such regular redirect:

<?php
header('Location: http://domain.com');
?>


...I need to call the URL in from another php file instead of http://domain.com, so something like that:

<?php
header('Location: <?php include("file.php");?>');
?>


File.php has the right url in it (generated with API code). But it doesn't read the php code in php redirect. How to make it work?

Answer

Try this:

file.php

<?php 
    // Determine your URL and assign it to $url
    $url = "http://example.com"; 
?>

File with header redirect

<?php 
    require_once('file.php');
    header('Location: '.$url);
?>
Comments