Jump to content
xisto Community
imajin8shun

I Need A Re-direction Script I need a script...

Recommended Posts

I'm looking for a re-direction script to re-direct you form one page to another automatically within the space of a few seconds. Like say I type
http://www.galcomm.com/
I want the script to activate straight away or within a few seconds to take them to like ww.sitename.com/file.php.I've looked through good-tutorials, phpfreaks, kirupa, html-goodies, and I couldn't find a script. can anyone help. HTML, PHP, JavaScripts are the kind I'm looking for, prefeably html or php.Note: I didn't know where to post this seeing as I'm looking for one of three different types of scripts.

Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

That's very easy, without any scripting language, just in HTML.

put this tag in the header of your page:

<head>    <meta http-equiv="refresh" content="6; // The time before re-direction in secondsurl=http://forums.xisto.com/no_longer_exists/ https://f; // The link to re-direct to</head>

Share this post


Link to post
Share on other sites

There are many simple codes out there to redirect, and Dynamic Drive (DHTML Scripts) offers this more complicated one:

<script>//Browser redirect Script- Š Dynamic Drive (
http://www.dynamicdrive.com/
full source code, 100's more DHTML scripts, and Terms Of Use, //visit dynamicdrive.comvar browser_type=navigator.appNamevar browser_version=parseInt(navigator.appVersion)//if NS 6if (browser_type=="Netscape"&&browser_version>=5)window.location.replace("PAGE URL FOR SOMEONE USING NETSCAPE 4")//if IE 4+else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)window.location.replace("PAGE URL FOR SOMEONE USING INTERNET EXPLORER")//if NS4+else if (browser_type=="Netscape"&&browser_version>=4)window.location.replace("PAGE URL FOR SOMEONE USING NETSCAPE 6+")//Default goto page (NOT NS 4+ and NOT IE 4+)elsewindow.location="http://
http://www.dynamicdrive.com/
;

As you can see, that enables people to go to different places depending on their browser.. Not entirely necessary, of course, but nothing ever is. And never use a blank page to redirect - always put a "redirecting in x seconds, click here if your browser is being disobedient" link.

Share this post


Link to post
Share on other sites

CODE

<?php
header('location: astahost.com');
?>


This is a script for url forwarding given by someone in a thread of the forum "PHP".
You said you need the code in PHP. I hope this can help you.

Share this post


Link to post
Share on other sites
whistle said:

<?php
header('location: http://astahost.com');
?>

 

This is the way to do it. Some browsers and firewalls block META refreshes and some people don't have javascript turned on, but a redirect done by HTTP document moved works always. Its the professional, stylish and also easiest way to do it.

Share this post


Link to post
Share on other sites

This is the way to do it. Some browsers and firewalls block META refreshes and some people don't have javascript turned on, but a redirect done by HTTP document moved works always. Its the professional, stylish and also easiest way to do it.

<{POST_SNAPBACK}>


It seems that there is a limitation in that code. No other codes can be placed before the header. If you hope to leand a file first and then to do the redirection, this will dispoint you. For examples, if you hope to put the code <? include "config.php"; ?> before header, it will says header has been sent. The DHTML code would be a better choice if you want your code more flexible.

Share this post


Link to post
Share on other sites

There is a way to do it from your cPanel.Rather than waiting, it redirects you straight away.Under Site Managment, click Manage Redirects (forth down on the right). The rest is pretty easy to figure out, so I'll leave you to it.Hope this helps, saxsux :-)

Share this post


Link to post
Share on other sites

It's easy to do redirection by adding a command in htaccess. The htaccess file is a file which a server will look up first before serving a page. Go edit your .htaccess file, usually found in public_html folder and add the following line:

Redirect /page1.html http://forums.xisto.com/no_longer_exists/

The page1.html is the page you want to redirect, its position relative from the public_html folder. The address that follow points to the page you want your visitors to be reditrected to.

Share this post


Link to post
Share on other sites

I'm looking for a re-direction script to re-direct you form one page to another automatically within the space of a few seconds. Like say I type http://www.galcomm.com/ I want the script to activate straight away or within a few seconds to take them to like ww.sitename.com/file.php.

 

I've looked through good-tutorials, phpfreaks, kirupa, html-goodies, and I couldn't find a script. can anyone help. HTML, PHP, JavaScripts are the kind I'm looking for, prefeably html or php.

 

Note: I didn't know where to post this seeing as I'm looking for one of three different types of scripts.

 


Hi, is very easy, you can do it with html using a meta tag http-equiv=refresh or with php using the header(Location=) function. For example using html you can put this in your head section:

 

<meta http-equiv="refresh" content="5; url=file.php">

it will instruct the browser to wait 5 seconds and then redirect to the file.php.

 

Now, using PHP you have 2 options:

Direct redirection:

<?phpHeader("Location: file.php");?>

With a time interval redirection:

<?php// wait 5 seconds then redirectSleep(5); Header("Location: file.php");?>

of course there will be other ways to do the same.

 

best regards,

Share this post


Link to post
Share on other sites

It seems that there is a limitation in that code. No other codes can be placed before the header.

This is not true, what is true is that there can be no output (to a browser) no HTML at all, I use it after processing a form and entering new data into the database and then sending the user either to a welcome page or another page immediately after filling in the fields. The header() function may be used anywhere in the script so long as you place it somewhere within that script that produces no output, what do you thinkis happening when you fill out the registration data here on this site, you are being redirected with a header, you are not clicking any links and somehow that data got placed into a database while you were being sent to the next part of the registration process.

Share this post


Link to post
Share on other sites

The best way to do it is to send the redirection status code for the HTTP/1.1 protocol (3XX) which automatically gets sent when using the PHP header('Location: someaddress/page') function, unless a status code has already been sent. The meta refresh is not a good idea, because it breaks the back button.

Status code 301 for permanent redirect or Status code 302 for temporary.

<?phpheader('Location: http://thisaddress.com/page.html');exit;?>

Should always make sure to exit too, incase there's code after it that you don't want to process before being redirected. There's other ways to do it too, which requires .htaccess file and URL rewriting or using the redirect derivative but avoid using meta refresh.


Cheers,


MC

Share this post


Link to post
Share on other sites

This is not true, what is true is that there can be no output (to a browser) no HTML at all, I use it after processing a form and entering new data into the database and then sending the user either to a welcome page or another page immediately after filling in the fields. The header() function may be used anywhere in the script so long as you place it somewhere within that script that produces no output, what do you thinkis happening when you fill out the registration data here on this site, you are being redirected with a header, you are not clicking any links and somehow that data got placed into a database while you were being sent to the next part of the registration process.


Yes, if you code properly it is easy to use header() and other functions like session_start() and setcookie() which requires that no output would be send before they are called, as a matter of fact it is best to output your site at the end of script after everything has been execute, but an alternative to this is to use output buffering, earlier a lot of whom did not use it, because they were "afraid" that something might be wrong and were avoiding ob_start() function, but a lot of whom saw the potential to use it and saw that everything works clean, I use it myself and now I usually don't have problems with it, but you need to get used to it and use it properly too. :lol:

and sometimes using the Refresh header, which brakes the back button is good, especially if you want to break it and that users could not browse back to them and you can use it not only by meta tags, it is the same with header() function:

<?phpheader("Refresh: 0; URL=\"file.php\"");?>

And the code can continue if you want it to parse something, just add some more seconds for the header, the browser will redirect. But remember, that Refresh header is not the Standard of HTTP, Most browsers just support it and thats all, so be careful when using it, the alternative is to use flush() with sleep() but this is crazy. :lol:
Edited by Quatrux (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.