htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Redirect to a different page without htaccess
PostPosted: 28 Nov 2006 00:51 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
Here are the non-php/non-htaccess ways to redirect, both go in the <head></head> section of your html. When I use non-php/non-htaccess redirects, I usually use both the refresh method and the javascript method, just to be safe.

Refresh method
Code:
<meta http-equiv="refresh" content="0;url=http://goto.com" />


Javascript method
Code:
<script type="text/javascript">
window.location.href='http://goto.com';
</script>


Ultimate PHP method from php.net
Code:
<?php
function g_redirect($url,$mode)
/* It redirects to a page specified by "$url".
* $mode can be:
* LOCATION: Redirect via Header "Location".
* REFRESH: Redirect via Header "Refresh".
* META:  Redirect via HTML META tag
* JS: Redirect via JavaScript command
*/
{
    if (strncmp('http:',$url,5) && strncmp('https:',$url,6)) {
        $starturl = ($_SERVER["HTTPS"] == 'on' ? 'https' : 'http') . '://'.
        (empty($_SERVER['HTTP_HOST'])? $_SERVER['SERVER_NAME'] :
        $_SERVER['HTTP_HOST']);
        if ($url[0] != '/') $starturl .= dirname($_SERVER['PHP_SELF']).'/';
        $url = "$starturl$url";
    }
    switch($mode) {
        case 'LOCATION':
        if (headers_sent()) exit("Headers already sent. Can not redirect to $url");
        header("Location: $url");
        exit;
        case 'REFRESH':
        if (headers_sent()) exit("Headers already sent. Can not redirect to $url");
        header("Refresh: 0; URL=\"$url\"");
        exit;
        case 'META':
        ?><meta http-equiv="refresh" content="0;url=<?=$url?>" /><?
        exit;
        default: /* -- Java Script */
        ?><script type="text/javascript">
        window.location.href='<?=$url?>';
        </script><?
    }
    exit;
}
?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot], MSNbot Media and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB