Jump to content


Photo

Looking for the a simple solution, if possible RE: page tracking


  • Please log in to reply
14 replies to this topic

#1 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 04:50 PM

I have a client who has a VERY basic site (12 html pages).

If a user signs up their info is put into a mySQL db and then they can sign in (using their email and password) to access 20+ html pages.

My question:
My client would like to see what users went to what pages on what dates.

Right now for the login I just check to see that the email/password exist and then they get re-directed to a "logged in" page (actually just a new directory).

How can I put a date and what page next to the user who visited it.

The easiest solution would be appreciated. (They really didn't pay for this much...but that's another story)  Is this something that can be done with cookies?

Thanks!

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 05:01 PM

A cheap and simple solution would be to store that info in the MySql db.

At login store the username in the $_SESSION['username'] variable.

Create a table: counter, columns: username, pagename and date, where:
username  = user's name, can be taken from $_SESSION['username'] variable
pagename = the name of the visited page
date        = the timestamp for the visit to the page

At the beginning of each page you do some PHP/MySql with the following:
INSERT INTO counter (pagename,username,date)
    VALUES ($_SERVER['SCRIPT_FILENAME'],$_SESSION['username'],time())

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#3 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 05:14 PM

Thanks a lot.

One more question:

I don't have a $_SESSION variable.

The form I have just checks to see that their email is in the DB and then redirects them to a new directory.

Is this method going to work?



#4 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 04 August 2006 - 05:40 PM

If you're not using sessions how do you know users haven't just gone straight to the new directory without logging in first? I.e. how are you authorizing access to these new pages?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#5 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 05:49 PM

yeah, that's the thing.  I brought this up to my client and they didn't really care.  They just wanted to gather some info on those looking for more information.  I told them that anybody could access this "logged in" area if they just put the correct url in.  They didn't mind and just wanted it done as easy as possible.  So, I quickly just did it the way they asked.

So, the question is..

Does this screw me when trying to track somebody who just logged in or can I just create the session variable now?

#6 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 05:54 PM

King Arther is right. You must check if a user is logged in at every page.
And how else would your client know who visited the pages?

Login page:
session_start()
setup $_SESSION variable['username'] containing username
write visitor record to counter table

Every other page:
session_start()
check is username is set in $_SESSION['username'] variable
if not: redirect to login page
otherwise: write visitor record to counter table

That's basically it!

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#7 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 07:47 PM

Thanks, this helped out a lot.

I'm just having trouble on the other pages:

I have:
<?php
	mysql_query("INSERT INTO memberlist (email,pagename,date)".
      "VALUES ($_SESSION['email2'],$_SERVER['SCRIPT_FILENAME'],time()");
?>

I get an error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in mysite.php on line 3



#8 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 07:57 PM

Try:
$sess=$_SESSION['email2'] ;
$scr=$_SERVER['SCRIPT_FILENAME'];
echo "INSERT INTO memberlist (email,pagename,date) ".
      "VALUES ($sess, $scr, time()";

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#9 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 08:09 PM

The page renders, but on top I get:

INSERT INTO counter (email,pagename,date) VALUES (, /com/mysite/public_html/page1.php, time()



#10 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 08:15 PM

Are you sure the email address is in variable $_SESSION['email2']? Because that one is empty.
Your sure it is not just $_SESSION['email']?

Btw pass he variables within single quotes like

echo "INSERT INTO memberlist (email,pagename,date)".
      "VALUES ('$sess', '$scr',".time().")";


Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#11 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 08:34 PM

First off, Thanks ronverdonk for being patient with me, you're being VERY helpful!

Second, I think I'm missing some fundamentals here (please bare with me)...
 
On my login page I have:

session_start();
$_SESSION ['email2'] = $email2;

//write visitor record to counter table
   $result=MYSQL_QUERY("INSERT INTO counter (email)".
      "VALUES ('$email2')");

I checked my table and it successfully writes my email to the email field.

Now if I sign in with a different email it will write the SAME email into the counter table.  I assume this is because of the session_start(); and no logout....


That's part I.

Part II

I'm still unclear on what exactly I should have on my other pages that will record where they are.

Do I connect to the database again on each page?  IE (mysql_connect...etc.) and do I use session_start(); on these pages?

Thanks so much!

#12 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 09:09 PM

First, I hope your code doesnot look like you quoted. The session_start should be at the very beginning.
Then you handle your login and after that you set the $SESSION variable.
You can do a mysql_pconnect (persisten connect) once or a mysql_connect at each page.

Ronald  8)

RTFM is an almost extinct art form, it should be subsidized.

#13 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 04 August 2006 - 10:04 PM

I got it to work!

Now for some reason I'm having trouble writing it to my DB table???

The echo text came out perfect, why is this not writing to my DB:


session_start();

$sess=$_SESSION['email'] ;
$sess2=$_SESSION['visitor'] ;
$scr=$_SERVER['SCRIPT_FILENAME'];

	
      $result=MYSQL_QUERY( "INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', ".date('l dS \of F Y h:i:s A').")");


#14 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 04 August 2006 - 10:08 PM

Ignore this post.  I was stupid.


"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#15 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:09 PM

I assume that your date field is defined as a CHAR/VARCHAR data type. So this value must be inserted using quotes, like this:
"INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', '".date('l dS \of F Y h:i:s A')."')";

'Saturday 05th of August 2006 12:11:38 AM' must be within quotes.

RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users