473,804 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Website Session Tracking - No Builtin Modules

2 New Member
Hi all

My problem is that I am creating a session file on the server when the user first visits my website, but when the user logs in i want to write to the file again with the timestamp and their userID.

Code snipet

Expand|Select|Wrap|Line Numbers
  1. if ($core->cookie(-name=>'ChasSession') eq "") {
  2.     if ($sID eq "") {
  3.         $sID = int(rand 1e9);
  4.     }
  5.     else{
  6.         $sID = $core->param('sID');
  7.     }
  8.     $cookie = $core->cookie(
  9.         -name        => 'ChasSession',
  10.         -value        => $sID,
  11.         -expires    => '+7d',
  12.     );
  13.     $file = "session.$sID";
  14.     printHeader("true");
  15. }
  16. else{
  17.     printHeader();
  18. }
  19.  
  20. open (SESSION, ">$file") ;
  21. flock SESSION, "2";
  22. print SESSION "lastActive:". localtime()."\n";
  23. print SESSION "userID: $userID";
  24. flock SESSION, "8";
  25. close (SESSION);
  26.  

this is the first run through it does this
and this works as I want it to.

But when i call a sub (when the user submits their username and password) and try to re-write to the file it doesn't work.

Expand|Select|Wrap|Line Numbers
  1. sub CorrectLogin {
  2.     open(LOGIN, "<.htpasswd");
  3.     flock LOGIN, "2";
  4.     $user = shift;
  5.     $pwd = shift;
  6.     $page = shift;
  7.  
  8.     if (($user eq "") || ($pwd eq "")) {
  9.         printDefaultBody("1");
  10.     }
  11.     else{
  12.         while (<LOGIN>){
  13.             @userpwd = split(":", $_);
  14.             chomp;
  15.             $tmpUser = @userpwd[0];
  16.             $tmpPwd = @userpwd[1];
  17.             $tmpPwd =~s/\s*$//g;
  18.             $salt = substr(@userpwd[1], 0,2);
  19.             if (($user eq $tmpUser) && (crypt($pwd, $salt) eq $tmpPwd)) {
  20.                 open (SESSION, "<$file");
  21.                 rename ("$file", "$file.old");
  22.                 open (NEWSESSION, ">$file");
  23.                 while (<SESSION>) {
  24.                     print NEWSESSION "lastActive:". localtime()."\n";
  25.                     print NEWSESSION "userID: $user";
  26.                 }
  27.                 login($user);
  28.                 printPageX($page, $file);
  29.                 return;
  30.             }
  31.         }
  32.  
  33.         if (($user ne $tmpUser) || (crypt($pwd, $salt) ne $tmpPwd)) {
  34.             print "<div class = \"error\">Invalid username and password </div>";
  35.             printDefaultBody("1");
  36.         }
  37.     }
  38.  
  39.     flock LOGIN, "8"; #unlock
  40.     close(LOGIN); #close file
  41. }
  42.  
Hope this is enough information for somebody to help me.

Charles


EDIT: It is for an assignment for University and I am not allowed to use any of the inbuilt modules
May 21 '07 #1
3 1579
KevinADC
4,059 Recognized Expert Specialist
try chomping before splitting:

while(<LOGIN>){
chomp;
@userpwd = split(":", $_);
###chomp;
May 21 '07 #2
Charles Abetz
2 New Member
The login part works fine too, what my problem is second time i use SESSION file handle, it doesn't write to the file that is created previously.
May 22 '07 #3
KevinADC
4,059 Recognized Expert Specialist
add some debugging and see if it helps:

Expand|Select|Wrap|Line Numbers
  1. open (NEWSESSION, ">$file") or die "can't open $file: $!";
nearly all system commands, such as open, should be checked for success or failure as a habit.
May 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
4760
by: Yang Li Ke | last post by:
Hi guys, Im about to build a script which will log visitor time spent on my website. I got a few ideas about this, maybe checking visitors ip and storing that info in db with time in and then using session vars to check time out ... Anyone has any ideas about doing that kind of script? Thank you! -- Yang
1
2762
by: marslee | last post by:
I am a php newbie. I would like to count how many times a user visit a webpage. I know session tracking should be used, but where i put the code? Is it inside the html that the user visit? session_start(); if (!IsSet($page_number)) $page_number = 1; print("You have now visited $page_number"); print(" of pages <br />");
2
5476
by: David Frauzel | last post by:
I'm writing a rough draft of a suite of small Perl apps that will, combined, serve as a web site's user sign-up, login, management, and customized content engine. I'm having trouble with the concept of one particular part of the "application" (as it were) - session tracking. Perl itself is handling user authentication (since I've no idea how Perl could "ask" the server who just authenticated to htaccess), so the login script will have an...
10
2472
by: Harry Slaughter | last post by:
I've got a client who wants to see some immediate results on a brand new website. within a week, they'd like to see the following: 1) basic user authentication (using php sessions/cookies to maintain authentication) 2) some basic content (text, photos, audio) uploading mechanism 3) basic content browsing in a somewhat neatly formatted presentation knowing how quickly they wanted something they could look at, i initially suggested...
2
1298
by: Casey Hawthorne | last post by:
Is there a way to determine -- when parsing -- if a word contains a builtin name or other imported system module name? Like "iskeyword" determines if a word is a keyword! -- Regards, Casey
3
2129
by: C G | last post by:
Dear All, I wonder if anyone can advise me with this problem. 1. A user logs into the database (through web, webservice, some other piece of software) - connect(user="joe",passwd="blogs") 2. We generate a random session key which will expire in 1 hour. Put this in table (user, SessKey, time). 3. Give key to user. 4. User wants to do something else, so passes us the session key.
1
2010
by: DDK | last post by:
Does anyone know if there are any books that talk about building a website tracking program for asp.net and C#? Or even any good resources on the web that talk about this. Thanks for any info, D.
43
3440
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
0
1176
by: =?Utf-8?B?YWRhdmlzLmRldg==?= | last post by:
Currently, we have an ASP.NET 1.1 application where there exists several "sections". We are upgrading the application to .NET 2.0 and want to seperate these sections into individual VS projects (05) and virtual directories (i.e. Domain.com/Section1, Domain.com/Section2, etc). This would allow us to develop / deploy the modules without worrying about affecting the other sections (i.e. cannot move Section 1 code changes until Section 2 has...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9571
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.