Jump to content

Variable Page Redirect


SyntheticShield

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.