/    Sign up×
Community /Pin to ProfileBookmark

JS redirect works in IE, not in Firefox

I have this in the <head> of a page:

[CODE]// first check if they have logged in before, and if so take them straight to index.php
var cookieVal = getCookie(‘Login’);
if (cookieVal) window.location=”index.php?userID=”+cookieVal[/CODE]

This is a login page — if they’ve been here and logged in before, and the cookie is still set, they shouldn’t even see the page. I just heard a complaint from one of our users that they have to use IE to access our site. Did some checking, fixed a couple of things, but this one’s got me flummoxed.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 21.2005 — If their IE is blocking javascript, there's nothing more you can do with that approach.

Since you have php, it would be better to do this on the server-side. I believe there's a $_COOKIE autoglobal you could use, something like[code=php]<?php
if(isset($_COOKIE["login"])) {
header("Location: index.php?userID=".$_COOKIE["login"]);
}
?>[/code]
Remember that since this sends a header, it has to go before you write any output, or it might not work (especially if PHP output buffering is off).
Copy linkTweet thisAlerts:
@strBeanauthorOct 21.2005 — You're right that I need to go with PHP for everything. This is one of the last vestiges of JS in my site.

But the problem here is that it works in IE and not in Firefox, on my machine, with JS enabled in both applications.

I think I'll go ahead and get rid of this last JS snippet, but I am a little curious as to what gives...


Thanks!
Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 21.2005 — Is it possible IE was blocking the cookie? Does IE give any sort of error message, or does it just sit there?
Copy linkTweet thisAlerts:
@strBeanauthorOct 21.2005 — It's Firefox that doesn't do the redirect, not IE. The cookie is set; it works with both JS and PHP when I use IE. I even tried deleting the cookie and starting from scratch.

I've just tested the PHP redirect. IE handles it correctly. Firefox displays the page as if the redirect script weren't even there.
Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 25.2005 — And you're sure firefox has the cookie (checked the cookie manager)? Also, go to about:config in firefox and filter for "redirect" to see if it's set to not follow redirects for some reason.
Copy linkTweet thisAlerts:
@strBeanauthorOct 25.2005 — It appears that Firefox isn't setting the cookie. I'll do some more experimenting and post again.
Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 27.2005 — Another thought:

Are you setting the expiry for the cookie? The default is for the cookie to expire th the end of browser session (when the browser closes).
Copy linkTweet thisAlerts:
@strBeanauthorNov 29.2005 — Sorry -- never got back here to say that it's working now. I don't remember what the last thing I tried was, but it's working. Come to think of it, I think I'm setting the cookie with PHP, so I never solved the mystery, but my curiosity isn't killing me.

thanks...
×

Success!

Help @strBean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...