A little help with my counter

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

A little help with my counter

Post by waskelton4 »

Hey group..

I've got a few questions...

I'm bulding a counter for my website and know what i'd like to have it do and know how i'd like to implement it, but i guess i need to know if what i want to do can actually be done..

What i'm wanting to do is buld some code, with PHP and JS, that serves as a counter for the web page..

What i'd like to do is "install" it in each web page by simply including the counter files in the code.

ie..

Code: Select all

<script language="javascript" src="getSpecs.js"></script>

<?
include(counter.php);
?>
Where the js file gets some browser specific data an the php file actually does some checking and logs the page load into mySQL.

From what i've been reading i'm not sure that this is possible because in order to actually get the js data to counter.php i'll have to submit the js data somehow..

is that what i'm looking at? Would it be better to log the js data on the next page loaded and send a page identifier along with the data telling mySQL where to put the js data?

any advice would be greatly appreciated..

also, if that makes no sense.. please let me know :)

Thanks
Will
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

javascript is (mostly) performed client-side while php is (almost all the time) done serverside.
if your page is provided via a php-able server the client will only 'see'

Code: Select all

<script language="javascript" src="getSpecs.js"></script> 

<- output from counter.php->
you have to send the results from getSpecs.js within a new request.

always remember: when a http-document is served, it's served and the connection (from http's point of view) is dead.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

But I think you could use the js code to set hidden variables that the php script will use on the receiving page. Alternative the js code add parameters to URL, set cookies (I think) etc with the values you want...
Of course this means that your counter lags one page view (ie the values that the determines are only entered into your database when the user views the next page.)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

"Where the js file gets some browser specific data" <- what data do you think of?
Maybe the browser is sending those values freely (version, etc.)
waskelton4
Forum Contributor
Posts: 132
Joined: Mon Sep 09, 2002 6:42 pm

Post by waskelton4 »

From volka:
Where the js file gets some browser specific data" <- what data do you think of?
Maybe the browser is sending those values freely (version, etc.)
Primarily screen resolution and color depth...
I also want to kind of experiment with the differences between navigator.appName and $_SERVER['HTTP_USER_AGENT']

if navigator.appName provides names for enough browsers then i probably won't mess with getting the browser names out of $_SERVER['HTTP_USER_AGENT']
Thanks for the help.
will
CodeEye
Forum Commoner
Posts: 25
Joined: Fri Jul 05, 2002 7:19 am

Post by CodeEye »

it is possible to send a message back from the browser if it is dom compliant check out
http://www.dotvoid.com/article_condensed.php?itemID=9

you will only need to updat it once so you can get rid of the timer
Post Reply