UBB.Dev
Hello everyone!
This board is a great resource!

I've looked at all the posts about cookies I could find...too many haha and I was wondering if you all could help me.

I want to store the user's post count on log-in to the cookie file.

Then I want to be able to read that post count from the cookie using javascript.

I have this for reading the cookie:
Code
<script language="Javascript1.1" type="text/javascript">
<!--

var session_cookie = getCookie('sessionBOARDSESSIONNUMBERREMOVED');
if (session_cookie == null) {
var session_dt = "0";
var session_j = "0";
} else {
var session_array = session_cookie.split("&");
var session_dt = session_array[0];
var session_j = session_array[1];
}

function getCookie(name) {
var cname = name + "=";
var dc = document.cookie;

if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) {
end = dc.length;
} // end if
return (dc.substring(begin, end));
} // end if
} // end if
return null;
}

//-->
</script>
and I've also looked through the ultimatebb.cgi where it stores cookies, but I keep doing something wrong.

Any help is appreciated. I am running version 6.7.

Thank you!
smile
Why do you need this info in a cookie? Can't you read the user number from the cookie server-side and get their profile information from that?
I agree what you said makes more sense. I am very familiar with ASP and ASP.NET but not so much with this perl/cgi integration I'm seeing in the ubb. This was the ghetto easy way I dreamed up haha.

I would just call the file open command where that file equaled the user number, then parse through that file for the post count? Is the post count stored in a variable location elsewhere that I could call?

I'm very new to modding a bulletin board of this size.

Any insight you have is helpful.

Thank you for replying.
Take a look at https://www.ubbdev.com/ubb/ultimatebb.php/topic/8/3690.html

There is a list of the member profile fields. Using PHP, you can just parse the file into an array and grab the appropriate field. I'm guessing you could file open and fetch the proper line in the file. Keep in mind that each of those fields in that list is a separate line.
Thanks for the link, ok I'm thinking of sticking with javascript to do all this.

I'm having trouble finding a good javascript "open the file and parse through it" tutorial...familiar obviously with how to parse the text once inside.

Anyone have a quick code they could share to open say user 0000001.cgi parse through it for line 7 then store that in a variable?

Sorry to sound so naive, but I learn best by example.

Thank you.
https://www.ubbdev.com/ubb/ultimatebb.php/topic/17/1031.html

The script in that thread does something similar, you'd only need to modify it slightly
Javascript is client side, no file opening there. smile
ugh this is what i get for trying to do this at work...*puts a dunce cap on.

i'm just going to do it with perl...im extremely rusty with it - ill post up what i get...

thanks again ya'll

smile
Ok I've parsed the post count.

Anyone got a plain php way to read the board cookie for user name without using any includes...just straight up read the cookie, grab the display name...etc. no noncgi paths, var_config includes...just straight up reading it and displaying it.

Basically the PHP equivalent of this:

Code
 <script language="Javascript1.1" type="text/javascript">
<!--

var session_cookie = getCookie('session2453335.1958');
if (session_cookie == null) {
var session_dt = "0";
var session_j = "0";
} else {
var session_array = session_cookie.split("&");
var session_dt = session_array[0];
var session_j = session_array[1];
}

function getCookie(name) {
var cname = name + "=";
var dc = document.cookie;

if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) {
end = dc.length;
} // end if
return (dc.substring(begin, end));
} // end if
} // end if
return null;
}

//-->
</script>

<script language="Javascript" type="text/javascript">
<!--
var user_cookie = getCookie('ubber2453335.1958');
if(''==user_cookie &#0124;&#0124; null==user_cookie) {
document.writeln('You are not logged in.' , ' <a class="top" href="http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=login">Login</a> or <a class="top" href="http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=agree">register</a>')
} else {

var user_array=user_cookie.split("&");
user_array[2] = unescape(user_array[2]);
document.writeln('Hello, ', user_array[2]);
document.writeln('[ <a class="top" href="http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=logoff">'
,'<acronym title="Click here to log out.">'
,'log out</acronym></a> ]');

}
//-->
</script>

I've tried several ways and it keeps displaying nothing.

Thanks everyone - a lot of good posts in this forum - i think i've worn out the search button.
Code
<?php

if(!isset($_COOKIE["ubber2453335_1958"])) {
echo 'You are not logged in. <a class="top" href="http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=login">Login</a> or <a class="top" href="http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=agree">register</a>';
} else {
$user_array = explode("&", $_COOKIE["ubber2453335_1958"]);

echo "Hello, $user_array[2] [ <a href='top' href='http://www.poorreflection.com/cgi-bin/ultimatebb.cgi?ubb=logoff'><acronym title='Click here to log out.'>log out</acronym></a> ]";
} // end if

?>
This one worked for me.
Thank you!

It worked laugh
© UBB.Developers