SyntheticShield Posted January 19, 2012 Share Posted January 19, 2012 Im not sure that it is possible, but I thought I would post and ask anyway. I want to use a page redirect such as: <?php header("Location: http://www.redirect-to-home.com/"); exit; ?> However, due to the nature of the redirect and the header having to be sent first, Im not sure how I could use a variable or probably better, something like HTTP_HOST. In a post I made elsewhere on here, someone posted this code: if($_SERVER['HTTP_HOST'] == "localhost"){ // For local development define('SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/template'); define('SITEPATH', $_SERVER['DOCUMENT_ROOT'] . 'template'); } else{ // For production web define('SITEURL', "http://" . $_SERVER['HTTP_HOST']); define('SITEPATH', $_SERVER['DOCUMENT_ROOT']); I began thinking then, I wonder is something like that could be used as a page redirect as a very basic and simple prevention to direct access to a specific folder on the site? But Im not sure how to make it work, Im just not that experienced in PHP yet. I dont know if using an index.html file would be better over an index.php file either. Im still experimenting a little trying to figure things out. So is there a way to use a php variable to redirect someone back to the home page? I know you can use .htaccess and things like that as well, but I wanted to see if this could be done also. Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/255328-variable-page-redirect/ Share on other sites More sharing options...
SyntheticShield Posted January 19, 2012 Author Share Posted January 19, 2012 Uggggh, nevermind, I got it. I was all off base, LOL if($_SERVER['HTTP_HOST'] == "localhost"){ // For local development define('SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/template'); define('SITEPATH', $_SERVER['DOCUMENT_ROOT'] . 'template'); } else{ // For production web define('SITEURL', "http://" . $_SERVER['HTTP_HOST']); define('SITEPATH', $_SERVER['DOCUMENT_ROOT']); } $URL= SITEURL; header ("Location: $URL"); Quote Link to comment https://forums.phpfreaks.com/topic/255328-variable-page-redirect/#findComment-1309091 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.