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 #4

Session Start: Tue Mar 12 13:59:22 2002

Session Ident: #scriptschool

*** Now talking in #scriptschool

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

*** Set by Kenny on Sun Mar 10 22:47:04

-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...

<venturi> hiya TDavid!

*** jvastine has joined #scriptschool

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

<TDavid> hello there ;)

<hwyman> hi Jvastine

<TDavid> how are you guys doing today?

<hwyman> hi TDavid

<jvastine> hi TDavid, hwyman, venturi!

<venturi> hi jvastine

<venturi> better. lots better. :)

<jvastine> running a little behind TD, but that's the norm.

<hwyman> hey there Venturi..i didn't see u standing there lol

<TDavid> we're going through week #4 today: http://www.pornresource.com/scriptschool/week4.php

<venturi> lol, I stayed up until 7am this morning getting caught up on my assignments.

<TDavid> things are starting to get more difficult now

<TDavid> i could tell from reviewing some assignments that by me not putting all the code in one nice neat table, it made it more difficult

<hwyman> gulp

<TDavid> you having trouble hwyman?

<hwyman> can't cut and paste anymore

<hwyman> lol

<hwyman> but I look forward as we go

<TDavid> we started out by adding 3 new variables to setup.php

<hwyman> yes

<TDavid> these variables are important for determining the directory path where we will store the log files ($dirpath)

<TDavid> and for redirecting trapped no referral ($noref) and nosendto codes ($nosendto)

<TDavid> then we created our own function which we called trackClick() which controlled all the file operations

<TDavid> did anybody have any trouble understanding variable scope inside functions?

<TDavid> i noticed one case on the assignment where there appeared to be confusion

<TDavid> ?

<venturi> nope I'm cool with scope

<TDavid> how do you explain scope, venturi?

<jvastine> hadn't gotten that far yet.

<hwyman> are we talking order in operation like math here?

<venturi> scope is this tasty blue liquid you gargle with.

<venturi> lol, j/k

<TDavid> we are talking about how variables can be used inside a program

<TDavid> ;)

<venturi> it is how functions, scripts, programs have visibility to variables

<hwyman> k

<venturi> basically.

<TDavid> variables inside functions *unless you specify otherwise* are private property to the function

<TDavid> so if we have a variable named $i OUTSIDE our function

<TDavid> and a variable named $i INSIDE the function, this doesn't create a conflict inherently

<TDavid> unless we need to use the value of $i in both places

<TDavid> if we do, then we need to declare that variable as global inside the function so that we can use it throughout the rest of the code

*** SleazyBear has joined #scriptschool

<TDavid> hello sleazybear ;)

<venturi> does php differ from perl on this point TD?

<SleazyBear> hi TDavid

<SleazyBear> just looking for dokk

<TDavid> give him a call :)

<SleazyBear> i did, no one answers

<TDavid> hmmm, you try dropping him email too?

<SleazyBear> did that too

<SleazyBear> lol

<TDavid> lol, well sorry that's what I'd do lol

<TDavid> if i see him i'll tell him you're looking for him ;)

<SleazyBear> yeah he is just out of pocket

<SleazyBear> ok thanks TDavid

<TDavid> don't be a stranger!

<SleazyBear> no one is ever stranger than me

<SleazyBear> lol

<SleazyBear> I know I need to get around more

<TDavid> as for the answer to your question, venturi, scope can differ between the languages quite a bit

<TDavid> so it is important to read up on the specific documentation for language on scope

<venturi> i was specifically referring to the usage of globals.

<TDavid> my answer is the same

<venturi> lol. point taken. :-)

<TDavid> it can get kind of confusing to talk about different languages so i try to stick to just the one at hand

<TDavid> so does my explanation of globals make sense (for php)?

<venturi> it does to me

<hwyman> I understand the globals

<SleazyBear> goto go, catch you all laters, thanks TDavid

<jvastine> sure

*** SleazyBear has left #scriptschool

<TDavid> so this does what:

<TDavid> global $dirpath, $refer, $sendto

<TDavid> specifically?

<hwyman> global is like declaring

<jvastine> allow all functions and programs to use the contents of these variables

<TDavid> are all those variables?

<TDavid> $dirpath, $refer, $sendto

<hwyman> yes

<TDavid> you sure?

<venturi> it makes the three vars $dirpath, $refer and $sendto visible and accessible inside function clickTrack()

<hwyman> no

<TDavid> $sendto is an array

<TDavid> it contains two elements

<hwyman> ok

<TDavid> the important point being here that you can pass variables and arrays

<TDavid> so if $sendto contained 1000 elements, you would make all those elements available to the function

<TDavid> in our example sendto only contains 2 elements

<jvastine> but isn't an array a variable that can have multiple dimensions?

<venturi> hehe, I call arrays variables with multiple elements.

<TDavid> well technically yes, jvastine ;)

<venturi> TD, is your point that we could have said: global $sendto[1] and thereby limited the scope to just that element of $sendto?

<TDavid> well if you only wanted to access one part of an array you might pass it as an argument

<TDavid> or return it from a function

<TDavid> i've never tried doing what you suggest, venturi, i'm not sure if that can be done

<TDavid> at least I don't remember ever trying that lol

<TDavid> my point is arrays can contain variables and i think something that people sometimes have a hard time understanding is the difference between them

<TDavid> so when i say variable, i usually refer to it as a single containter

<TDavid> er container

<venturi> gotcha.

<TDavid> and an array is a multiple container

<hwyman> k

<jvastine> or the way you access their contents

<TDavid> something we aren't doing in our trackClick() function is returning a value

<TDavid> although we are passing it an argument

<TDavid> what is an argument?

<hwyman> if ifelse

*** Kre8t0r has joined #scriptschool

<venturi> a parameter, whether a constant value or variable/array that is passed to a function or procedure

<TDavid> ok, venturi, but in english lol

<jvastine> a variable passed to a function

<Kre8t0r> lol

<venturi> ROFL

<hwyman> hi Kre8tor

<TDavid> hi kre8tor

<venturi> hey Kre

<Kre8t0r> hey folks

<jvastine> hey kre8tor

<TDavid> i liked to describe an argument as: "Something passed to a function for use"

<TDavid> it can be a variable, a filename, a condition, a function result

<TDavid> like in our example we are passing to the trackclick function the name of the file

<venturi> you bring up the term "container", in php are functions, etc. considered as containers? and if so can they be "passed"?

<jvastine> redundant - why pass it if it's not used

<TDavid> jvastine, whatever you pass can be used as a form of a trigger

<TDavid> so it can be something that is used or not, but the argument itself is usually not optional

<jvastine> true, my point was you said to pass to use...why pass if it's not used - a trigger would be used, correct?

<TDavid> and yes, venturi, functions themselves can be passed

<TDavid> that's a great question, think about why that might be done

<TDavid> jvastine

<TDavid> how about an error message

<jvastine> to determine the logical path

<TDavid> rather than making the $error global you pass the value

<TDavid> function errorMsg($error)

<venturi> cool, so it is then not necessary to do this:

<venturi> $i = myfunction($foo);

<venturi> myOtherFunction($i);

<venturi> instead you can do this:

<venturi> myOtherFunction(myFunction($foo));

<TDavid> well if you want to assign the return value of myfunction to $i, unless $i is a global inside the function

<TDavid> i think the important part with functions isn't to get too carried away

<TDavid> they are powerful, but they are resource hungry

<TDavid> we are using trackClick() really in a situation where we don't even need to use a function at all

<jvastine> interesting

<TDavid> we could put the branch of code to at the bottom of the script and avoid using a function altogether

<TDavid> you might wonder why i bothered therefore to bring up functions at all

<TDavid> they have their place

<TDavid> if you benchmark the code (as we will do in week 6) you'll see that using a function versus not using one makes a difference

<venturi> at the simplest level, repetitive coding causes multiple points of maintenance and failure.

<TDavid> there is no need for repetition in this code, we could simply set the $filename variable to the value and at the very bottom of the code have the trackclick function

<TDavid> i was wondering if someone would bring up why there was a function at all

<venturi> the question did cross my mind. :)

<TDavid> again, it is here as an illustration and a lesson

*** Frank has joined #scriptschool

<Kre8t0r> if i had a clue i would have :p

<venturi> hiya Frank

<jvastine> hey Frank

<TDavid> now, let's say we have trackDB()

<Frank> Hi! Sorry I'm late. Just got up, hehe do we have audio?

<hwyman> hi Frank

<TDavid> nope, only Friday frank :)

<jvastine> no audio

<Kre8t0r> :p

<TDavid> we might write another function for using a database

<Frank> k, that's right

<TDavid> and then we could simply swap out the function call

<TDavid> an easy way to use multiple file structures

<TDavid> which was one of the things we were going to examine in this course

<TDavid> so now if you wanted to use a database, you wouldn't have to replace the code or have a bunch of code branches, you just swap out the function name

<TDavid> OR you could even pass as an argument, but then I wouldn't recommend doing that

<TDavid> because it would make the function fatter

<venturi> so, we could perhaps perform a test to see if the dB was available for connection and if not call the file IO version.

<TDavid> and as functions go, it is probably about as large as you want it to be

<TDavid> exactly, venturi

<TDavid> these are all programming tradeoffs

<TDavid> efficiency or ease of use

<TDavid> functions the majority of time are for ease of use and code reuse

<TDavid> and if efficiency is more important, than you can eliminate many of them

<TDavid> it does make the code more complex, but it can save a considerable amount of resources

<TDavid> in this case the complexity wouldn't really be there

<TDavid> ok, let's go to the counter

<TDavid> $thecount = 1;

<TDavid> $sendto[1] = str_replace("|", "~", $sendto[1]);

<TDavid> why do we do the line above?

<hwyman> filter out |

<TDavid> what is the pipe symbol in our data structure?

<hwyman> ok field seperators

<venturi> to ensure that the written log entries have exactly the same number of elements each time. The "|" is our delimiter.

<hwyman> ok

<TDavid> so if the pipe symbol was left, we'd have a mismatch in fields?

<TDavid> here's another good tip, always, always, always use str_replace() for doing single character swaps

<TDavid> do not use ereg_replace or preg

<TDavid> if you benchmark the difference in these functions for single character swaps it is ridiculous

<TDavid> one isn't performing a full regular expression and the other is, i think, though I haven't looked into the c source to see

<TDavid> for certain

<TDavid> if any of you guys are handy with C you can always view the php source code for answers on things, it can be enlightening

<TDavid> i guess that is the advantage of open source versus proprietary

<venturi> "handy with C" <-- oxymoron

<TDavid> yeah, i know some long time c programmers and they are still figuring out new, better ways to do things lol

<TDavid> it's a very humbling language lol

<TDavid> and then there is assembly! lol

<Frank> hehe, I wish I knew alittle of anything about any language, hehe

<TDavid> ok, i digress ... $newline = time()

<TDavid> that assigns the unix timestamp to $newline

<TDavid> and then we concatenate (add) to the string:

<TDavid> "|$refer|$sendto[1]"

<venturi> I had a problem with that concatenation

<TDavid> yes?

<venturi> when $refer and/or $sendto[1] were empty it buggered up the log writing for the 'generic' log file

<venturi> and I saw some notes on "explode" that made me wonder how multiple adjacent delimiters were handled

<venturi> to get the log to write correctly, I had to perform a test and insert *anything* into those elements for it to write correctly.

<TDavid> well it is actually important for those to be left empty

<TDavid> or soon you will see when we get around to the stats

<venturi> I'm talking about the writing to the sysdefgen.txt log. :)

<venturi> sorry, couldn't remember the file name for a sec.

<TDavid> hmmm, interesting

<venturi> it was not updating existing entries for that log. always appended to the file.

<TDavid> it's a good exercise :)

<venturi> i was going to mention that in my assignment post, but it was 7am and I'd been up all night.

<TDavid> sometimes, as in the case of pazz, you have to have some trouble to learn about things

<TDavid> not that having trouble is a good thing necessarily, but pest control is a vital part of the programming world

<TDavid> there is another inherent flaw with the sysdefgen.txt file

<TDavid> do you know what it is?

<TDavid> or is there?

<TDavid> I throw this out for food for thought for next week

<Kre8t0r> lol

<venturi> not that I can see in mine. :-)

<Kre8t0r> keep em on their toes TD?

<TDavid> i am getting spammed by some fucker named sandam hussein -- fuck you sandam!

<venturi> lol

<Kre8t0r> tell him the planes are on the way

<TDavid> so are you using this on some actual pages, venturi, yet?

<venturi> just the test pages I created

<TDavid> after this week 4 you should be able to start actual tracking on pages

<venturi> have been thinking about putting it into action this week though.

<TDavid> i have to attach some pages on my sites this week

<TDavid> because it is necessary for stats for next week to have some actual data

<TDavid> frank, how you doing, mon?

<venturi> I've got a couple pages I'm very curious to watch

<TDavid> has this met our goal of being easy to integrate with existing pages?

<TDavid> does anybody know?

<Frank> ok TDavid, still alittle sick, gotta cold.

<TDavid> i guess that is your assignment between now and Friday. Stick this code up on a few actual sites and start tracking them

<TDavid> make sure you test each link though so that it goes where it is supposed to

<TDavid> that would suck if you didn't go to a sponsor on a live page

<venturi> LOL, yep. would really suck

<TDavid> and remember to consult the sponsor TOS to make sure it is ok to use a script like this

<TDavid> when in doubt, ask

<TDavid> they can't throw you out or deny your payment if you get written approval (well they can, but not without looking really bad lol)

<TDavid> i think with publication like the statistician there is a loosen up of this in TOS

<TDavid> but that's just my opinion, not a fact

<venturi> :-) given the sites I'm really curious about are pointing to a fellow student's program I'm not too concerned right now. lol

<TDavid> well any general questions about this week's assignment or the week 4 course text? I know there is some code we didn't get to, but we'll cover that on Friday

<TDavid> i read one student say this week took 7 hours to do

<TDavid> i hope it doesn't take that long

<TDavid> supposed to be 4-6 at the most

<Frank> I'm sure you'll see me posting questions in the assignment area, lol

<hwyman> me to lol

<venturi> week 3 actually took me longer than this one (self inflicted tho')

<TDavid> any general commments about the course text? Are you finding this reasonably easy to follow?

<hwyman> I'm gonna learn or die trying lol

<Frank> well, I gotta admit. Between some personal issues, being sick, and biz I have fallen behind alittle. But I'll catch up.

<TDavid> well the beauty of this is that you can take it any time

<jvastine> the same here, I'm still in catch-up mode.

<TDavid> like i said before, i am still answering questions on the first php course and that was august of 2000

<TDavid> though as more of these courses come to realization I do start getting things confused a bit lol

<venturi> I *think* I'm caught up, but I'll reserve the right to retract that claim after TDavid reviews my wk3 & 4 assignments. :-)

<Frank> TDavid, the course text seems always to be just fine. It's just that someone like me that had never done one ounce of code before is always gonna be a bit confused,LOL but that's what questions are for, hehe

<TDavid> there's some 50,000 words worth of course material now! lol

<Kre8t0r> kool guess i could start now then

<TDavid> absolutely kre8tor, it's never too late ;)

<Kre8t0r> i can always bug venturi for the stuff i missed :p

<Kre8t0r> hehe

<Frank> Think I'll understand better when I get the lingo down and know what all the symbols do and such.

<TDavid> i'd listen to the audio too, because I think with this course we've stayed more on focus than the other ones in term of the audio recap part

<venturi> LOL, and "bugs" you will get my friend.

<Frank> Just like electronics

<Kre8t0r> ok kool

<TDavid> ok, well i'm going to jet unless you guys have anything else

<TDavid> keeping it light today

<jvastine> nothing here TD

<hwyman> thanks for your help TDavid...everyone

<venturi> nope. I've gotta run too and see about rescuing my puppy from the hospital. :)

<Kre8t0r> plenty to keep me busy

<TDavid> oh man, hope that goes ok venturi

<Kre8t0r> have a good one TD

<TDavid> thank you for showing up guys

*** Disconnected

Session Close: Tue Mar 12 15:07:10 2002

Amazon Honor System




Copyright 2000-2008 KMR Enterprises
Privacy Statement