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 -
if ($core->cookie(-name=>'ChasSession') eq "") {
-
if ($sID eq "") {
-
$sID = int(rand 1e9);
-
}
-
else{
-
$sID = $core->param('sID');
-
}
-
$cookie = $core->cookie(
-
-name => 'ChasSession',
-
-value => $sID,
-
-expires => '+7d',
-
);
-
$file = "session.$sID";
-
printHeader("true");
-
}
-
else{
-
printHeader();
-
}
-
-
open (SESSION, ">$file") ;
-
flock SESSION, "2";
-
print SESSION "lastActive:". localtime()."\n";
-
print SESSION "userID: $userID";
-
flock SESSION, "8";
-
close (SESSION);
-
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. -
sub CorrectLogin {
-
open(LOGIN, "<.htpasswd");
-
flock LOGIN, "2";
-
$user = shift;
-
$pwd = shift;
-
$page = shift;
-
-
if (($user eq "") || ($pwd eq "")) {
-
printDefaultBody("1");
-
}
-
else{
-
while (<LOGIN>){
-
@userpwd = split(":", $_);
-
chomp;
-
$tmpUser = @userpwd[0];
-
$tmpPwd = @userpwd[1];
-
$tmpPwd =~s/\s*$//g;
-
$salt = substr(@userpwd[1], 0,2);
-
if (($user eq $tmpUser) && (crypt($pwd, $salt) eq $tmpPwd)) {
-
open (SESSION, "<$file");
-
rename ("$file", "$file.old");
-
open (NEWSESSION, ">$file");
-
while (<SESSION>) {
-
print NEWSESSION "lastActive:". localtime()."\n";
-
print NEWSESSION "userID: $user";
-
}
-
login($user);
-
printPageX($page, $file);
-
return;
-
}
-
}
-
-
if (($user ne $tmpUser) || (crypt($pwd, $salt) ne $tmpPwd)) {
-
print "<div class = \"error\">Invalid username and password </div>";
-
printDefaultBody("1");
-
}
-
}
-
-
flock LOGIN, "8"; #unlock
-
close(LOGIN); #close file
-
}
-
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
3 1579 KevinADC 4,059
Recognized Expert Specialist
try chomping before splitting:
while(<LOGIN>){
chomp;
@userpwd = split(":", $_);
###chomp;
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.
KevinADC 4,059
Recognized Expert Specialist
add some debugging and see if it helps: - 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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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 />");
|
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...
|
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...
|
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
| |
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.
|
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.
|
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.
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |