Forum Moderators: phranque

Message Too Old, No Replies

Redirect to main page... HOW?

         

doucetted

11:44 pm on Mar 20, 2005 (gmt 0)

10+ Year Member



I run a server hosting several free web sites.

On one site I would like to force visitors to read a message before allowing them to navigate to other parts of the site.

In this way if someone were to link to say index2.html they would be redirected to index.html then once they click a button after reading the message they are directed to index2.html

Any help would be appreciated!

specter

7:13 am on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try to add this tag in the "index2.html" page:

<META http-equiv="REFRESH" content="0; url=http://www.myname.com/index.htm">

Regards

JKMitchell

11:13 am on Mar 21, 2005 (gmt 0)

10+ Year Member



I think that this would never let the visitor see index2.

Try looking at some sort of pop-up on the 'onload' of index2, although some pop-up blockers would mean that the visitor may not get it.

giggle

12:21 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



You could always use a simple form:

<form method=POST action="index.htm" name=FormId>
<input type="submit" name="ClickButton" value="Click Here">
</form>

doucetted

3:05 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



OK I have figured out how to set a cookie with the value of "copyright" to expire when the browser closes, I put this code in the first page (index.html) and it seems to work fine...

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
createCookie('www.mysite.com','copyright',0)
function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
var ck = name+"="+value+expires+"; path=/";
document.cookie = ck;
}

// -->
</script>

Now here is the tricky part, I put the following code in the second page (index2.html)...

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
go_to = "http://www.mysite.com/index.html";

function readCookie('www.mysite.com')
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
window.location = go_to;
}
// -->
</script>

What I want to do is if the cookie doesn't exist or is null then go to index.html otherwise just continue loading this web page. This script is not working.

Any help?

Reid

6:10 am on Mar 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what kind of server is it?

doucetted

6:16 am on Mar 22, 2005 (gmt 0)

10+ Year Member



linux

running apache

MichaelBluejay

12:54 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you assuming that users enter only through the home page? If you want to catch users entering at any page in your site, then I'd use a Rewrite rule in your <.htacess> file to redirect users to the login page, with a form on that page that redirects them to wherever they wanted to go in the first place. For example:

RewriteCond %{REQUEST_URI}!redirecter
RewriteRule (.*) [yourdomain.com...] [L]

That will redirect a request for <yourdomain.com/subpage.html> to <yourdomain.com/redirecter.cgi?subpage.html>

Your <redirecter.cgi> file is a Perl or PHP script that displays the log in page, with a link back to the page the user first tried to go to. It grabs the file for that page from the query string in the url.

I did something like this after the presidential election where anyone entering any page of my personal site was first shown a splash screen of a picture I commissioned of the statue of liberty holding a gun to her head.

I imagine jdMorgan will chime in here if I screwed the code up, if he checks out this forum....

Reid

9:11 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What was Liberty doing with her other hand?