Script School Student Workshop Logs
Home $ News @ LIVE Tech Radio $ PHP Course @ Perl CGI Course $ Enroll @ Support/FAQ $ Store

Script School is made possible
by these fine sponsors

Enroll Today here!


The following (edited) log is for the "How to build a Clicks Out" Course Week #3

 

Session Start: Tue Mar 19 13:40:53 2002

Session Ident: #scriptschool

*** Now talking in #scriptschool

*** Topic is 'Week #4 Clicks Out Course LIVE Audio Recap: $$ Script School - Learn More so you can Earn More $$$ Next Radio Show: Friday Mar 15, 2002 2pm PT / 5pm ET'

*** Set by ssjanitor on Fri Mar 15 13:13:14

-Kenny- Welcome to TDavids Script School. Brought to you by Webmaster Live, Albumside and Your Host, TDavid!

*** Kenny sets mode: +o TDavid

*** Retrieving #scriptschool info...

*** TDavid changes topic to 'Week #5 Clicks Out Course Workshop: $$ Script School - Learn More so you can Earn More $$$ Next Radio Show: Friday Mar 22, 2002 2pm PT / 5pm ET'

*** Taz has joined #scriptschool

<Taz> hey there

<TDavid> hello taz :)

*** TDavid sets mode: -o TDavid

*** TDavid is now known as TD-phone

<Taz> is there a way to pass arrays from one page to another

<Taz> in php]

<TD-phone> yes

*** TD-phone is now known as TDavid

<TDavid> <input type="hidden" name="varname[]

<TDavid> oops

<Taz> but it is not from a form

<TDavid> use sessions then

<TDavid> or cookies, but i'd recommend sessions

<TDavid> you are too limited with GET

<TDavid> or POST

*** jvastine has joined #scriptschool

<Taz> it is a search the info comes from a form but spread over multi pages

<Taz> i got it to work on way but the url kinda long

<Taz> http://www.cdnsingles.com/test/results2.php?offset=25&age1=18&age2=95&gender=2

<TDavid> again, best way is to use sessions and pass along the session url in the query string

<Taz> i need to put this in a array and pass it with the url or some how to the $php_self

<TDavid> those long urls are fine for admin areas, but they are not good for public sturff

<Taz> age1=18&age2=95&gender=2

<TDavid> you get into url encoding/decoding it can be a nuisance lol

<TDavid> i wouldn't get in the habit of using $PHP_SELF either

<TDavid> have you taken the PHP courses at Script School? We go through some of this

<TDavid> ?

<TDavid> hello jvastine, btw :)

<Taz> nope i have not annieb only told me about this place two days ago

<Taz> after 2month of programing my singles site in php

<TDavid> are you the same Taz i know?

<TDavid> if so we've talked about this site before in the past :)

*** hwyman has joined #scriptschool

<TDavid> you might want to look into the serialize function as well as a possible solution for what you are doing: http://www.php.net/manual/en/function.serialize.php

<Taz> humm i don't think you know me

<hwyman> hello folks

<TDavid> Your name start with a "B"

<TDavid> ?

<Taz> nope

<Taz> i am fom canada

<Taz> too

<TDavid> ahh, well there is a fairly well known webmisstress who uses the name "Taz"

<TDavid> she is from On The Ropes.com

<Taz> ahh

<TDavid> you might have trouble with that nick from those who've been around awhile

<TDavid> maybe you want to be Canada_Taz hehe

<Taz> i have been using taz in the industry for like 6-7yr now

<Taz> i have been here a while too

<jvastine> Hi TD, didn't mean to ignore you, I'm bouncing between aps at the moment...hope all is well with you this week!

<TDavid> hmm, ok, well i'm no spring chicken and this is the first I've talked to you lol

<TDavid> seen the other taz lots of times though ;)

<TDavid> though i think you were in the FM chat on Monday too, yes?

<Taz> ya i don't run around on all the boards

<Taz> yes

<jvastine> hey hwyman, venturi, & Taz

<TDavid> well, whatever, I'm just letting you know I am confused anyway lol :))

<Taz> i don't know you may know my brother

<Taz> wolfe

<Taz> lol i know there are a few who are

<TDavid> yeah, i know wolfe, met him at the airport in Seattle one time

<venturi> HI folks!

<Taz> ya he is my brothere

<Taz> brothere

<Taz> oppps

<Taz> brother

<venturi> wheh! just got back from a run to the store

<TDavid> cool, he does some programming too :)

<TDavid> hi venturi :)

<Taz> ya he does

<venturi> thought I was gonna be late. ;)

<TDavid> did you get enrolled as a student, taz? http://www.scriptschool.com/enroll.phtml

<Taz> that the link i was looking for

<TDavid> we are about to start a workshop here, you are of course welcome to stay, but this is the week 5 workshop for the clicks out course

<TDavid> how you been, venturi?

<venturi> pretty good. We got invaded this weekend. Mishi's sister just popped in Saturday.

<TDavid> ahh, for the green beer celebration

<venturi> LOL, yup. I'm still recovering.

<TDavid> i have been doing a lot of experimenting over the last week with speech synthesis

<TDavid> it has come a long ways over the years

<Taz> there we go enrolled

<TDavid> actually over the last year, i've been working on a project

<TDavid> cool taz :))

<TDavid> welcome!

<TDavid> i see nobody has really tackled week #5 yet

<TDavid> and some just catching up with week 4

<venturi> sorry, I was just about to do just that when Nicole came pounding at our door Sat. :)

<TDavid> no need to be sorry :)

<venturi> it's on the list for tonite though. :)

<venturi> I'm a naughty schill student. LOL

<TDavid> i suppose we should dig into the material now. The URL for the course material is located here:

<TDavid> http://www.pornresource.com/scriptschool/week5.php

<TDavid> This week we'll start working on the admin.php script and learn how to generate and output stats to the browser-based admin area. We'll start by focusing on the daily log file that automatically archives itself every day (where there is a click registered).

<TDavid> we are creating a new function in the admin area to handle the dynamic dropdown box

<TDavid> so that we can reuse this box across every record in our data directory

<TDavid> this way we simply pass a filename and a file extension to it to generate the <SELECT> drop down menu

<TDavid> dropDown('logs_', '.dat'); <-- would generate all logs files

<TDavid> which end in .dat (which is all of them)

<TDavid> we can even pass a search criteria to this form using the filename suffix

<TDavid> this is a handy technique to employ for reusing code

<TDavid> using an argument passed to a function for a search criteria

<TDavid> let's examine the drop down code

<TDavid> the first two lines:

<TDavid> function dropDown($match, $ext) {

<TDavid> global $dirpath;

<TDavid> venturi, you with me?

<venturi> yeah, catching up a bit but I'm with you I think. :) sorry, just got in and have a billion messages. Telling people to leave me alone for the next hour. LOL

<TDavid> I must leave a little early today, so i'm going to go through this fairly fast

<hwyman> k

<TDavid> we went through what the global statement did last week in depth

<venturi> okay, I think I'm caught up.

<TDavid> now if we remember we set the permissions for the datadir (data directory) to be amenable so that we could read the files in the directory

<TDavid> depending on the permissions at a higher level this can be a different, but usually chmod 777 will allow this

<venturi> yup

<TDavid> i don't want to get tied up on permissions, because that could be a class in itself

<TDavid> but if you have trouble with this function and get permission denied errors, try making sure that the permissions are 777

<venturi> LOL, yup. no need to talk sticky bits here. :)

<TDavid> or amenable for file reading

*** Pazz has joined #scriptschool

<TDavid> ok, this is the code line by line to get the files in the directory

<TDavid> hi pazz

<TDavid> first we open a filehandle

<TDavid> $handle = opendir($dirpath);

<Pazz> Hey there TDavid and gang

<TDavid> next we read that handle:

<TDavid> while (false !== ($thefile = readdir($handle))) {

<TDavid> this line of code might give you a headache at first when you read it, but basically it is saying to keep reading until the end of the list of files

<TDavid> if ($thefile != "." && $thefile != "..") {

<TDavid> that line seeks to ignore the parent and child directories

<TDavid> i call them parent and child directories but there might be a better more precise technical term for them

<venturi> with ya. :)

<TDavid> i kind of have my own vocab with things sometimes lol

<TDavid> if (eregi($ext, $thefile)) {

<TDavid> this line will examine the extension and apply to the filename

<TDavid> if it matches the file extension then we proceed to examine the contents, if it doesn't then we ignore

<TDavid> if(eregi($match, $thefile)) {

<TDavid> this matches the filename criteria, caseINsensitively

<venturi> ah! that what the 'i' in eregi means?

<TDavid> now that we've passed these checkpoints, we have a match, and let's create the <OPTION> values for our dropdown menu

<TDavid> print("<option value='$thefile'>$thefile</option>");

<TDavid> then we have a series of closing } for the conditions

<TDavid> the important part to note is the tabbing and alignment so that the statements do not become confused

<TDavid> if you don't tab and keep your code organized in some way like this, then you can become confused

<TDavid> we've discussed this before, but it is a point worth mentioning repeatedly

<venturi> yep. that's why I always close my statement blocks before I fill in the rest of the code.

<TDavid> lastly we close the open filehandle:

<TDavid> closedir($handle);

<TDavid> and then close out the function

<TDavid> }

<TDavid> So as I said, it is now easy for us to create a dynamic dropdown list for our daily log stats

<TDavid> by simply passing code like this:

<TDavid> dropDown('logs_', '.dat');

<TDavid> now as you notice there are components missing here

<TDavid> like where is the beginning of the <SELECT> and the ending of the </SELECT>

<TDavid> why wouldn't we include those in the code?

<hwyman> html tags maybe?

<venturi> to keep the function simple?

<TDavid> you guys are close, but there is something obvious here

<TDavid> what does the select consist of?

<venturi> and the form we're building will likely be more complex than a select box?

<hwyman> options

<TDavid> we could pass as a third argument a name for the select function

<TDavid> <select name="XXX">

<TDavid> but I like to leave that outside so that we can use different names if we want

<venturi> so we could build multiple selects and use the same function to build them all?

<TDavid> yes

<TDavid> more variation possibilities

<venturi> cool

* venturi likes generic functions. :)

<TDavid> also if you remember we created options in the admin.php

<TDavid> it is time to return to those options and change one of them

<TDavid> we are going to make optiona = view log stats

<TDavid> when clicked now it will go to a form with our drop down menu of files

<TDavid> er log files that is

<TDavid> each day where there was at least 1 click thru registered, there will be a log file

<TDavid> as you might remember, that is how we setup the script to create the logs

<TDavid> based on the day

<TDavid> kind of a self managing system for logging

<TDavid> now let's look at the form to create this code

<TDavid> print('Please choose the daily log stats you want to review<p>');

<TDavid> print("<form method='post' action='admin.php'>

<TDavid> <input type='hidden' name='pt' value='1'>

<TDavid> <input type='hidden' name='action' value='showdaily'>

<TDavid> <select name='filename'>");

<TDavid> dropDown('logs_', '.dat');

<TDavid> print("</select> <input type='submit' value='View All Daily Stats'></form>");

<TDavid> you'll note that I kept it inside a print() and didn't exit PHP to create the form

<TDavid> you could choose to exit php and use straight HTML

<venturi> what are the pros and cons of doing so?

<TDavid> again, if you ever want to benchmark to see if there was a performance penalty, refer to our previous workshop logs for that discussion

<TDavid> well the pros of doing so is that if you have PHP variables you can just insert the name

<TDavid> the con might be that it becomes more difficult for non-php programmers/webmasters to edit

<venturi> hehehe, that might not be a con. ;)

<TDavid> many designers I work with seem to have trouble the more code that is inserted inside the pages

<TDavid> especially if the designer uses some type of editor that isn't a straight text editor

<Pazz> Speeking of workshop logs http://www.scriptschool.com/php/c5101/logs5_4.phtml doesn't work

<TDavid> yes, pazz, neither is last week's audio archive up yet

<TDavid> i have them, but it might not be for a few days until i get those items up.

<TDavid> Another reason I encourage people to come to these LIVE

<TDavid> lol

<venturi> hahaha

<TDavid> no guarantee when i'll get the archives posted

<TDavid> definite guarantee i'll be here :)

<Pazz> I'm here today :)

<hwyman> nods with a smile

<TDavid> btw pazz, make a note to show up at the radio show today

<Pazz> In how many hours is it?

<TDavid> you were venturi and i nod for the week 4 amazon prize, but you must be there to claim

<TDavid> er radio show friday i mean, sorry

<TDavid> i know it is like 7am australian time

<venturi> if you have ICQ, netsurprise will send you a reminder both one hour before the show and when it starts.

<TDavid> but for $50 gift certificate, maybe worth getting out of bed one day lol

<hwyman> yes

<TDavid> if you aren't there, it will be awarded to someone else who has done the week 4 assignment

<TDavid> and it will be awarded within the first 15 minutes of the program

<TDavid> just FYI :))

<Pazz> Didn't the prize go off on the llaast show

<venturi> hint-hint, nudge-nudge

<TDavid> and week #5 ... well, that is for the taking since nobody has done week #5 yet lol

<TDavid> so maybe pazz you could score $100 gift certificate this Friday lol

<Pazz> Mental note: have less beer Friday so I can get up early Saturday :)

<venturi> rofl

<TDavid> lol

<TDavid> ok now that we have created the form

<TDavid> when the admin clicks on the log that they want to view

<venturi> see. save money AND maybe win cool stuff

<TDavid> we will go to a detailed screen

<TDavid> let's go through the layout of this detailed screen

<TDavid> I setup a very simplistic table

<TDavid> with the following fields:

<TDavid> Timestamp Referring Page Send Click To following Page ~ CODE Clicks Count

<TDavid> You will note that these records are already in "timestamp" order

<TDavid> so we can display the file chronologically without the need to sort them

<TDavid> We will make sure to add a &nbsp; to the end of each row

<TDavid> just in case the data is empty

<TDavid> so the cell is still drawn

<TDavid> we could wrap an if statement to check for it

<TDavid> but then we are doing additional testing that doesn't really matter (unless you don't want a space inside each cell)

<TDavid> now the plan will be to reuse this table open scheme

<TDavid> so let's create a function for opening the table

<TDavid> function openTable() {

<TDavid> ?>

<TDavid> <p>

<TDavid> <table border="1" width="100%">

<TDavid> <tr>

<TDavid> <td width="15%" bgcolor="#C0C0C0">Timestamp</td>

<TDavid> <td width="35%" bgcolor="#C0C0C0">Referring Page</td>

<TDavid> <td width="35%" bgcolor="#C0C0C0">Send Click To following Page ~ CODE</td>

<TDavid> <td width="15%" bgcolor="#C0C0C0">Clicks Count</td>

<TDavid> </tr>

<TDavid> <?

<TDavid> }

<TDavid> you will note here that I *did* escape PHP

<TDavid> and i did so to illustrate that you can also do this inside a function

<TDavid> which can be kind of handy to know

<venturi> that is cool. Wouldn't have thought to try that. :)

<TDavid> remember that this is an admin area and probably in a user area you wouldn't want to use a function like this

<TDavid> the reason being that designers may want to change the code

<TDavid> and as i've found when working with designers they can really tend to botch up code (unintentionally of course)

<TDavid> i tend to botch up their graphics, so we are even :)

<hwyman> lol

<Pazz> lol

<venturi> LOL, I tend to botch up both.

<TDavid> but since the admin area is essentially the area of one person

<TDavid> then you can employ techniques like this

<TDavid> to save you time and shorten your code

<jvastine> sounds cool

<TDavid> ok, now it is time to format the links so that we can generate new options inside the admin area dynamically

<TDavid> as i was saying before the course began to taz, inside admin areas there is really no harm in having long query strings

<TDavid> but if you are doing this in user areas it is really ugly and can cause problems

<TDavid> here is an example of a dynamic row in the table:

<TDavid> <td width=\"35%\"><a href=\"admin.php?pt=1&action=byref&filename=$filename&url=$eachline[1]\">$eachline[1]</a>&nbsp;</td>

<TDavid> notice that the action = byref

<TDavid> this is a NEW option and this is a "hidden" option

<TDavid> because it won't be part of the menu above. You might also refer to this as a sub-option

<TDavid> since it will happen once we've entered one of the main options

<TDavid> what this does is pass along the filename, the url to check and will resort this list by referrer

<TDavid> so when you as the admin click on the referrer then it will show you only clicks out by that referrer

<TDavid> for that day

<venturi> cool!

<TDavid> so as your clicks come in, this all happens dynamically, are you with me?

<jvastine> yes

<TDavid> I will now show you the byref option code

<venturi> i think so. we'll know better once we code it. LOL

<hwyman> yes

<TDavid> case 'byref':

<TDavid> print('sort by page referer');

<TDavid> this establishes that from the action we are going to sort by referrer

<TDavid> let's open the table

<TDavid> openTable();

<TDavid> easy, huh?

<TDavid> $all = file("$dirpath/$filename");

<TDavid> $sizeall = count($all);

<TDavid> $counter = 0;

<TDavid> let's dump the contents of our logs file into the array named $all

<TDavid> then we determine the size of that array ($sizeall)

<TDavid> and we define the counter as zero

<TDavid> er initialize

<TDavid> for($i=0; $i<$sizeall; $i++) {

<TDavid> $eachline = explode("|", $all[$i]);

<TDavid> next we start iterating through the array with the contents of the log file

<TDavid> we explode each line of data by the delimiter which is the pipe symbol as you'll all remember

<TDavid> next we see if the $url (which was passed in the code) matches the referrer line:

<TDavid> if($eachline[1] == $url) {

<venturi> so far, so good.

<TDavid> if it does, then we know to include this in our output

<TDavid> print("<tr>

<TDavid> <td width=\"15%\">$eachline[0]&nbsp;</td>

<TDavid> <td width=\"35%\"><a href=\"admin.php?pt=1&action=byref&filename=$filename&url=$eachline[1]\">$eachline[1]</a>&nbsp;</td>

<TDavid> notice again that the code is dynamic

<TDavid> we do the same thing with the sendto url so that we can break down how many clickthrus we sent out to a specific location

<TDavid> or even a location on a page using the a-z code that we setup

<TDavid> the code is slightly different and refers to another routine which is very similar

<TDavid> in fact, both the byref subroutine and the bysendto could be incorporated into a function

<TDavid> but I left the code in full so it would be easier to understand and follow

<TDavid> here is the dynamic code for the sendto url

<TDavid> <td width=\"35%\"><a href=\"admin.php?pt=1&action=bysendto&filename=$filename&url=$eachline[2]\">$eachline[2]&nbsp;</td>

<TDavid> notice that action = bysendto

<Pazz> Yep

<TDavid> and that the url is set to the sendto url

<TDavid> lastly we display the clickthru count

<TDavid> <td width=\"35%\"><a href=\"admin.php?pt=1&action=bysendto&filename=$filename&url=$eachline[2]\">$eachline[2]&nbsp;</td>

<TDavid> oops

<TDavid> <td width=\"15%\">$eachline[3]&nbsp;</td>

<TDavid> </tr>");

<TDavid> there we go hehe

<TDavid> and then we increment the counter

<TDavid> $counter++;

<TDavid> the $counter is used to tally up the links that matched the criteria

<TDavid> }

<TDavid> }

<TDavid> print("</table><p>There is a total of <font color='green'><b>$counter</b></font> clicks in <b>$filename</b> from page: <a href=\"$url\" target=\"new\">$url</a>");

<TDavid> then we close the case with:

<TDavid> break;

<TDavid> now I don't show you the bysendto routine, but it should be easy to put together with the example of the byref code

<TDavid> basically the two subroutines are the same

<venturi> hehehe, no more cut-n-paste assignments. :-)

<TDavid> nope, not really hehe ;)

<TDavid> that brings us to the assignment for week 5

<TDavid> Add the following stats options to admin.php: view all from daily logs, view by page referrer (by chosen log date file), view by send to page URL (by chosen log date file). Create two new functions: openTable() and dropDown() using the code described in the course text. Please post the complete admin.php source code with comments to the designated to-do folder and post link to your working admin.php DEMO script with a demo password.

<TDavid> in our final week of this course, we'll go through how to edit the log stats and the individual log files

<TDavid> from the admin area

<TDavid> we'll also discuss future options for the script

<TDavid> it's going to be somewhat short on course text, because I want to leave open room for us to discuss "how to" do things to add to this script

<TDavid> so do not expect a whole lot more info beyond what has been offered in this week

<hwyman> nods

<venturi> sounds good. :)

<TDavid> any questions, comments?

<Pazz> Cool

<jvastine> no questions, just need to get my ass to work!

<venturi> same here. Just gotta put on my coding boots and git bizzy.

<TDavid> now if you look back at the early course text and see up to week 5, is it all coming together for you?

<Pazz> Just a quick stupid question

<hwyman> no questions from me either...

<TDavid> shoot pazz

<Pazz> The case 'byref' is that just another section of code that sits with the options like case 'viewlogstats'

<Pazz> ?

<TDavid> yes

<TDavid> it takes place of the optiona optionb optionc placeholders that we made in the beginning

<Pazz> Clear as mud now :)

<Pazz> So I could delete optionc and replace with byref

<TDavid> no

<TDavid> you just use that format and add a new option

<TDavid> replace optiona with the viewlogstats

<TDavid> leave optionb and optionc

<Pazz> Mmm I knoew I missed something :)

<TDavid> because those are links to click directly from the admin area

<TDavid> and the other links are hidden/sublinks inside the code

<TDavid> they are not directly clickable

<TDavid> the options were meant for direct click

<TDavid> the other suboptions, of which there will be many i'm sure

<TDavid> are contained in the same select/case

<TDavid> next week we'll create optionb which will be edit data

<TDavid> or maybe we won't ... and we'll just add an edit button to the inside of the existing optiona

<TDavid> you have to think about which would be best :)

<Pazz> Ok that sounds good

<TDavid> i personally think if you are already looking at the data and want to edit or delete it

<TDavid> having the buttons there to do so are the best way to go

<TDavid> of course to illustrate how to do that, it might be easier to start from the outside and work in

<TDavid> next week stuff we'll cover next week, but you'll see what i mean when you begin to construct the code

<TDavid> be sure to ask any questions on the BBS if you have any

<Pazz> Of to have a look at one you prepared earlier :)

<TDavid> yes, what is in the course text should be all you need to build the code for this lesson

<TDavid> though admittedly it is not as easy as a simple cut and paste

<TDavid> any other questions, comments?

<TDavid> are you guys finding this course useful?

<Pazz> No more questions, that has given me a bit to do :)

<venturi> having a little difficulty visualizing how it's gonna look, but will dig in to the code. That'll give me an idea. :)

<TDavid> if you want to see a quick example you can look at my code

<hwyman> I am not understanding everything but learning as I go

<TDavid> http://www.scriptschool.com/php/c5101/admin.php

<TDavid> use the password: framework123

<hwyman> ok thanks

<TDavid> btw, this is just a demo, so it can't hurt to know

<venturi> OK! Gotcha now. :) thanks.

<TDavid> did you check it out?

<TDavid> if you go to those test pages I created and click the links you can follow along with it as it builds a new log file and logs the clicks

<TDavid> it's pretty slick actually ;)

<venturi> yup. just needed a quick looksie. I was confusing myself (easy task....)

<TDavid> has anybody tried using this script to begin tracking clicks on actual live pages yet?

<TDavid> you'll notice i added a refresh link too, which is handy to have so if you are sitting on one script and want to see the most current results you can just hit that

<venturi> I started to last week, but have basically been out of pocket since Saturday afternoon. I'm in extreme catchup mode. :)

<TDavid> one could even build in some meta refresh code say every 10 minutes or so and then just check back

<TDavid> it could even include some javascript to pop a box on you updating you of the activity

<TDavid> there really is no limit in where you can take this script ;)

<hwyman> nods

<Pazz> It's great, hope my version can be as good :)

<TDavid> ok, i'm heading out take care guys

<venturi> thanks TDavid! :)

<Pazz> I don't remeber seeing anything about the refresh though :)

<Pazz> Thanks TDavid

<jvastine> take care TD, and thanks for your time & effort.

<hwyman> bye TDavid

<Pazz> Cya Saturday

* TDavid closes log

<TDavid> cya friday! :))

<hwyman> later folks

*** Disconnected

Session Close: Tue Mar 19 15:08:40 2002


 

Amazon Honor System




Copyright 2000-2010 KMR Enterprises
Privacy Statement