/    Sign up×
Community /Pin to ProfileBookmark

Cookie Check and redirect

I want to check for a cookie if it does not exist i want to redirect to the login page if it does exist it does nothing can anybody help finish my code

code below

Madaxe

<HTML>

<HEAD>
<title>Janet Vice</title>
</HEAD>

<body bgcolor=”#000000″>

<SCRIPT LANGUAGE = “JavaScript”>
<!–
var name = GetCookie(‘janetvice.net’);
if (name != null)

<META http-equiv=”refresh” content=”0;URL=http://www.janetvice.net“>;

//–>
</SCRIPT>

</body>

</html>

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 16.2005 — [font=trebuchet ms]Shouldn't you be doing this with a server-side language? After all, some people might not have cookies or JavaScript, and as a result would not be able to login if you didn't provide this functionality regardless of the presence of JavaScript or cookies.[/font]
Copy linkTweet thisAlerts:
@madaxeauthorMar 16.2005 — SSL I think you mean CGI which is what most of my pages are written in but i dont know how to do it and im not sure if my use of html and cgi is correct but if i can do this with java it would save me some agro im just learning so if you could help that would be great


Madaxe
Copy linkTweet thisAlerts:
@JonaMar 16.2005 — [font=trebuchet ms]I prefer that you don't use the term "SSL" to abbreviate "server-side language," because SLL actually is an abbreviation that means "Secure Sockets Layer" and is used for encrypted web sites (e.g., sites that require credit card information).

You should do this in CGI because you can. Anything that cannot be done in CGI but can be done in JavaScript ([i]not[/i] Java) is different, but if you can do it in CGI, you should. If you need help to learn how to use cookies in CGI, you can just search Google. There are more than plenty of tutorials on it. (Besides, it only involves adding an additional header, which is a really simple step; the cookie should be available as a global variable from within most programming languages and CGI is no exception.)[/font]
Copy linkTweet thisAlerts:
@Warren86Mar 16.2005 — <HTML>

<Head>

<Script Language=JavaScript>

function init(){

if (!document.cookie){window.location.replace("http://www.janetvice.net")}
}

window.onload=init;


</Script>

</Head>

<Body>


</Body>

</HTML>
Copy linkTweet thisAlerts:
@madaxeauthorMar 17.2005 — Thanks for that

not sure how it works im a cgi java newby how does it look for my cookie i can see the redirect i think could you break it down and explain it


madAxe
Copy linkTweet thisAlerts:
@madaxeauthorMar 17.2005 — The way i see it there are threew steps

first

check for cookie which i have

second

load redirected page which is the piece f code i got from a reply

so how do i piece it all together


Madaxe

[code=php]
<HTML>
<Head>



<Script Language=JavaScript>


var name = GetCookie('janitvice.net');

if (name != null)

}



function init(){

if (!document.cookie){window.location.replace("http://www.janitvice.net")}
}






window.onload=init;





</Script>
</Head>
<Body>

<h2><font color="red"><b><u><center>WELCOME TO OUR NEW WEB SITE!!!!</center></u></b>

</body>

</html>

[/code]
Copy linkTweet thisAlerts:
@Warren86Mar 17.2005 — All right. You are intent upon changing the code I posted. A name isn't necessary if you have only ONE cookie for the site. I have nothing further to offer, and am unsubscribing from this thread.

Good luck to you.
Copy linkTweet thisAlerts:
@madaxeauthorMar 17.2005 — Look im sorry i have no idea how java works i tried your code and it did not seem to work, please dont be angry im trying to learn and im making mistakes


Madaxe
Copy linkTweet thisAlerts:
@Warren86Mar 17.2005 — It's not Java, it's JavaScript. They are not the same. And, I'm not angry. The code I posted works. I'm just not one to engage in this back and forth, back and forth, without good reason.

I'm not a teacher. I won't spend time teaching you or anyone else. You state that you tested my code, but obviously, you DIDN'T TEST IT AS IS. Key words: AS IS!

It's a regrettable and all too frequent occurance.

"I tried your code, but it don't work. I only made one simple change to it, so that it would work with my code, but now it don't work. Can you tell me why your code don't work with mine?"

No. End of the line for me.

Good luck.
Copy linkTweet thisAlerts:
@madaxeauthorMar 17.2005 — Hang on matey

in your last post you said i had to add your code to mine how? sorry i thiought your code was the whole snippet, did not mean to offend old boy new to forums coding and stuff. I do appreciate people posting to my questions please accept my apologies. Look im not the most intelligent person on this planet and im trying to teach my self something which is probably beond my grasp so a little help would be appreciated

Madaxe
×

Success!

Help @madaxe 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...