...

View Full Version : :: how can i check for cookies when...



babelfish
08-26-2004, 12:47 PM
i have 2 database websites set up on one server:

http://10.10.20.11/Cdatastore.nsf/welcome

http://10.10.20.11/KAMToolbox.nsf/latestAdditions?openview&count=10

now, due to the muppets in IT customising IE so much i have to run a .hta file to correct the registry etc so the first website forces the user to run the .hta file then sets a cookie.... so that it doesnt look to run the file on a return visit

now, ideally i would like to centralise the fix process and get the 2nd werbsite to simply check for the cookie that the first website has done - if not to forward it to that page...

is this possible? im not too hot with cookies (havent had time to look into them really) so keep it simple plz :)

thanks all!! :thumbsup: :thumbsup: :thumbsup:

glenngv
08-26-2004, 02:06 PM
Since both sites are on the same machine, the first site can set a cookie and specifying the cookie path as / (root) so that the cookie is also accessible to site 2. You don't have to specify the cookie domain since the default is the domain creating the cookie.

I don't know how you create cookies in Notes Domino but here's how to do it in javascript.

document.cookie = "domino_cookie=blah;expires=" + new Date("01/01/2010").toGMTString() + ";path=/";

Take note that if the user accesses the first site using IP address and a cookie is created and then the user accesses site 2 using hostname, the cookie will never be retrieved by site 2. The host from the domain name must matched.

Here's more info of the Cookie Specification (http://wp.netscape.com/newsref/std/cookie_spec.html)

babelfish
08-26-2004, 03:28 PM
thx m8... im actually not using notes for the cookie usage - just for the security and ease of database usage..

my cookie script page looks like this:



expDays = 365;

var fix = 'http://www.simonsintranet.com/files/fixes/fix240804.hta'
var fixdate = '24th August 2004';

var fix9x = 'http://www.simonsintranet.com/files/fixes/fix240804.hta'
var fixdate9x = '24th August 2004';

//change the fix number in $$HTMLHead and setNewCookie() function (2x places)

function launch() {
window.open(fix9x)
}

// ##########################################################################################

function updatefix() {

document.getElementById('fixer2').innerHTML = '<a href="javascript:history.go(-1)"><img src="continueicon.gif" border="0" align="absmiddle"> Click here to continue</a>';
}

// ##########################################################################################

function writefix() {

if(opsys!="Win 9x") {
document.getElementById('fixer2').innerHTML = '<a href="' + fix + '" onClick="setNewCookie(); updatefix()"><img src="mediicon.gif" border="0" align="absmiddle"> Fix for ' + fixdate + '</a>';
}

else {document.getElementById('fixer2').innerHTML = '<a href="javascript:;" onClick="launch() ; setNewCookie(); updatefix()"><img src="mediicon.gif" border="0" align="absmiddle"> Fix for ' + fixdate9x + '</a>';
}
}

// ##########################################################################################

function showCookieHistory() {

if(document.cookie!="") {
var cookieinfo = document.cookie.split('_')[1];
cookieinfo = cookieinfo.split('=')[0];
document.write(' | Most recent update: ' + cookieinfo)
}
}

// ##########################################################################################

function get_cookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return get_cookie_val (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function get_cookie_val(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function set_cookie (name, value,expires) {
var argv = set_cookie.arguments;
var argc = set_cookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function delete_cookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = get_cookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function checkCount() {
var count = get_cookie('poponce');
if (count == null) {
count=1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
set_cookie('poponce', count, exp);

//dothis()
}
}

function setNewCookie() {
var count = get_cookie('poponce_240804');
if (count == null) {
count=1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
set_cookie('poponce_240804', count, exp);
}
}

function dothis(){
document.location.href="fixespage"
}


i then check for the cookie by:



if((document.cookie.indexOf('poponce_240804')==-1) && (document.location.href.indexOf('fixes')==-1 )) {
document.location.href='fixespage'
}


when i synchronise the test environment to the actual server both will be on a server name 'notes1' but the second site will be in a subfolder on that server - hope that makes sense... i go on hols after tomorrow so im not really able to concentrate today! :D

babelfish
08-26-2004, 03:30 PM
btw - i modified the above script so if you see that i am doing thisng in a round-a-bout way plz tell me where im going wrong :)

glenngv
08-27-2004, 03:53 AM
I don't know what your exact problem is and what the hta is for.

babelfish
08-27-2004, 10:16 AM
i just need a way so that website1 can create cookies that website 2 can read - if that makes sense... - they will be on the same server

the HTA is just to disable content advisor, delete a couple of files on win95 (yes we still have 150 or so win95 users!!!) and do some reg fixes to change the way powerpoint is displayed

glenngv
08-27-2004, 12:17 PM
Since the 2 sites are on the same machine, you just create and read cookies as you normally do in a single site. You just have to set the path to "/" as I described in my first post.

babelfish
08-27-2004, 12:23 PM
doh! was a bit busy yesterday and didnt realise how easy that was! doh! thx m8!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum