Session Start: Tue Oct 17 11:59:33 2000 *** Now talking in #netsurprise *** Topic is 'WEBMASTERS ONLY!!!! Welcome to the Adult NetSurprise Chatroom!' *** Set by CrEaToR on Thu Oct 12 18:10:48 -SurpriseBot- Welcome - Net Surprise IRC - thud.net channel #netsurprise TD! hello there :) *** LaughingEyes has quit IRC (Connection reset by peer) busybusybusybusy ... anybody else? hehe :) test 123 test tw, i've got your deal on the list for today or tomorow, btw :) ahhh :) * TW scream WAAAAAAAAAAAAAAAAAAAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKEEEEEEEEEEEEEEEEEEEEEEEE UUUUUUUUUUUUUUUUUUUUUPPPPPPPPPPPPPP! *** CrEaToR sets mode: +o TDavid *** CrEaToR changes topic to 'Right Now: Tech Chat with TDavid! Ask Questions about Programming and the PHP Course! Welcome to the Adult Netsurprise Chatroom!' hiya TD =) hi creator :) let's see what's on the docket for today ... regular expressions so let's determine ways to regularly express ourselves and environment variables in PHP $HTTP_REFERER = <-- the page url the surfer came from $REMOTE_ADDR = <-- the IP address of the surfer this is the course url we are discussing, btw: http://www.adultnetsurprise.com/learning_center/php/php_week_7.html a somewhat complete list of environment variables available to you in php is here: http://www.php-scripts.com/php_diary/environment_variables.html if you have questions about what each of these environment variables do, feel free to ask *** tia has joined #netsurprise but the best way IMHO is to simply output them to your browser and see another common one besides $HTTP_REFERER and $REMOTE_ADDR is $HTTP_USER_AGENT that helps to tell you what type of browser the surfer is using it contains the name and version of the surfer's browser ... you can see this in use on the Netsurprise messageboard near the tagline *** sharkysr has joined #netsurprise as you might have seen that some manipulation of environment variables can take place, so using them as a sole method of determining a surfer's identity is fallable Howdy everyone. Thought I'd pop in for a few minutes *** Buzzard has joined #netsurprise as with any other type of security scheme you will want to use multiple independent checks to ensure the best security hiya sharkysr, buzzard, we are having Tech Chat hi tia buzzard and sharkysr :) hey :) oops...hey tia example: we check to see that the person submitting a url ... hey there 1. does the URL look like a valid url? 2. is the person submitting a form from a valid location (domain/page url) *** TW has quit IRC (Connection reset by peer) *** Jaggi has quit IRC (QUIT: User exited) just checking the ip or domain, again, can be fallable so it is important to check for multiple issues. Most hackers aren't wise enough to work through multiple checkpoints because many people simply don't do the work to check for things like this *** Buzzard has quit IRC (QUIT: User exited) so if you make sure all your form input "looks like" it is supposed to then you are ahead of the game that is the concept behind this week's course which is environment variables and regular expressions *** CrEaToR is now known as CrEaToR-aWaY *** WillyB has joined #netsurprise you can use these two tools to make sure that what you are getting is "clean" and not tampered for example, hackers will submit a form to your script from their website and attempt to breakdown your scripts if you pass items to a database or the shell directly this can be a HUGE security hole so if you listen to nothing else I say during this 16 week course, listen to this: never never NEVER pass unchecked data to a database or shell now let's look at a few ways to protect a form any questions thus far? nope $mydomain = "http://www.php-scripts.com/"; if(eregi("$mydomain", $HTTP_REFERER)) { ?> *** patrik_garrent has joined #netsurprise *** patrik_garrent has quit IRC (QUIT: User exited) now if you look at the code above there is a structural problem that may not be obvious at first *** patrik_garrent has joined #netsurprise we are checking to see if the surfer is coming from $mydomain ... which is php-scripts.com they can change the mydomain variable in their script? no then I don't know not if it is PHP but that is a good point, if we didn't assign $mydomain they COULD, couldn't they? the www could be a problem scriptname.php?mydomain=http://www.hackerdomain.com/ right but since we assigned mydomain in the script that ploy is foiled however what about the "www" ok how many people omit the "www" I do half the time if they came from simply "php-scripts.com" the regular expression would fail yet we want to allow the surfer to come from the comain php-scripts.com OR www.php-scripts.com so we need to tweak this regular expression a bit a couple of different ways to use a logical OR here we could simply make two urls Damn, I actually got one right... LOL $mydomain = "http://www.php-scripts.com/"; $mydomain2 = "http://php-scripts.com/"; if(eregi("$mydomain|$mydomain2", $HTTP_REFERER)) { the pipe | means or inside a regular expression so now we are saying if they come from either of those two preset domains they are ok :) but as i've said before it is a good idea to practice eliminating redundancy whenever possible. the http:// part is redundant in the code above hi hi patrik if(eregi("http://$mydomain|$mydomain2", $HTTP_REFERER)) { so now you can remove that part ça va but we can also go with just one url and check for the www - any ideas how? Does spacing inside of the regular expression have a bearing on it's outcome TD? yes every character has an outcome so if we left a space between / and $mydomain we'd be saying there needs to be a space there if(eregi("http://$mydomain|www.$mydomain", $HTTP_REFERER)) { would that work? no i don't think yes i think it might but there is a slightly better way to form that expression using only one variable it would put the http:// in the www part too? better to look at it like this: if(eregi("(http://)($mydomain|www.$mydomain)", $HTTP_REFERER)) { notice the parenthesis trapping in the components of the match that is useful for keeping reg exp clearer *** tia has quit IRC (QUIT: User exited) That does make more sense. but let's rewrite so that we only use one variable that would put http:// in front of the $mydomain or www.$mydomain then yes But you really don't need them around the http:// part do you? no you don't i just did that for illustration any ideas how to do it with just one variable? if(eregi("http://(|www.)$mydomain", $HTTP_REFERER)) { close, but nope, the period unescaped is a wildcard for any character except new line *** TW has joined #netsurprise if(eregi("http://(|www\.)$mydomain", $HTTP_REFERER)) { if(erigi(http://+$mydomain) if(erigi(http://+$mydomain, $HTTP_REFERER) if(erigi(http://+.\..$mydomain, $HTTP_REFERER) sharkysr you are correct Those damn pesky excape characters.... LOL http://(|\ <--- is nothing OR *** SurpriseBot sets mode: +o TW OK Patrik are you a webmaster? yeah the escape characters can be tricky at times *** patrik_garrent was kicked by TDavid (hmmm, i think you are looking for love in the wrong place) *** erika has quit IRC (Connection reset by peer) if(eregi(http://+.\..$mydomain, $HTTP_REFERER) wouldn't work for it without someting infront of it lol gave him the benefit of answering :) i think i see hehehe TW the + means one or more characters in that expression http://+ you'd be saying to have one or more / so the http:///////// would match :0 you could use http:(/{2}) to force 2 and ONLY 2 / you can do the same with the t ic h(t{2})p:(/{2}) looks like greek but really is pretty easy once you know the codes That is more work then just putting in what you want that is more complicated than sharkysr's answer! hehehe yeah, and unnecessary unless you exactly want to make sure of a certain pattern for instance a phone number area code is 3 digits regexp [[:digit]{3}] or maybe a zip code Right TD, in specific circumstances like that it would make alot of sense. ok, now a qestion.. if you were at TDscripts.com for example and typed in the url, which happened to be on your server, would it make the referer be your server as well? *** Chris has joined #netsurprise reg exp: ^([0-9]{5})(-[0-9]{4})?$ 5 digits followed by a dash - followed by 4 digits and must end with a digit and must start with a digit *** floppy has joined #netsurprise no willyb, any type-in url is going to be "" hello everyone;)) an empty string hi floppy bookmarkers usually show up that way too *** patrik has joined #netsurprise *** TW has quit IRC (Connection reset by peer) You can use the [0-9] and [:digit] interchangably? And is the : a required part of the digit? hey floppy [[:digit:]] yes ok, great! my lesson will work then :) i like digit because it makes it easier to follow a long string, but it is one of those "whatever you are more comfortable with" things Now you used two : that time... which is correct? two is correct OK. regexp [[:digit:]{3}] they are repeated in this week's course material as well you have other options like [:alpha:] [:lower:] [:upper:] etc is [[:alpha:]] the same as [[:lower:]] ? for me anytime I can write out a word like OR or AND instead of using || or && I am making the code more readable same for regexp no, [:lower:] requires lowercase only in the course material it says you can subsitute both with [a-z] yes because upper would be [A-Z] can alpha be upper and lower yes, any alphabetical letter regexp: ([:alpha:]{3}[:lower]) regexp: ([:alpha:]{3}[:lower:]) requires three alphabetical letters the case doesn't matter first three letters any case followed by lower case only? yup what if you wanted to force to be 3 lowercase letters followed by 3 upper case letters? *** Lady-EXXXstasy has quit IRC (Ping Timeout) regexp: ([:lower:]{3}[:upper:]{3}) *** erika has joined #netsurprise exactly what if you wanted to require at least 3 uppercase letters followed by at least 3 but not more than 6 lowercase letters? Good Question TD... *** TW has joined #netsurprise any guesses? what if you wanted to require at least 3 uppercase letters followed by at least 3 but not more than 6 lowercase letters? I'm thinking... and that may take awhile... regexp: ([:upper:]{3}[:lower:]{3,6}) <--- here, it is easier than it sounds if you separate by a , in the { } the second number is the max range if you leave just the , then infinity is selected to match But you said at least 3 upper case, not exactly 3 ahh, you caught that! hehe shouldn't there be a , after the 3 with nothing after that regexp: ([:upper:]{3,}[:lower:]{3,6}) <--- here, it is easier than it sounds Or does it work that way? space is optional in that case you can make it do two separate statements too I don't quite understand your reply TD [:lower:][:lower:][:lower:]{,} <-- would be at least 3 but more which part sharkysr? you don't need a space after the comma no well i doublechecked my reference manual and it shows the space there no I wasn't asking about the space, that is why I put up the example using{3,}. would that give you at least 3, with no upper limit? so i may stand corrected on this yes, 3 with no upper limit is {3, } no, that would give you EXACTLY 3 with no upper limit it was a trick question, sorry but it is the type of thing you will experience sooner or later when trying to construct a regular expression It says with one integer and a comma. says nothing about needing a space there TD.. i don't think the space is needed, i just doublechecked my book to be sure and it shows with a space so like i said originally i believe it is optional won't hurt either way *** WillyB is now known as willyB_afk sorry, I want to log this though.. I have to deal with some crap here at the moment so if want at least 3 we might need to use 2 instances of [:lower:] [:lower:]{3}[:lower:]{,6} like that hmm maybe 2 there for the first one [:lower:]{2}[:lower:]{,6} hehe that will force at least 3 and exactly 6 it can become a bit confusing dealing with reg exp, can't it? :) Without a doubt on that one TD.... haha the easiest way is to break down reg expressions in parts take them a section at a time instead of trying to chomp down the whole match at once it is easier to make them that way any other questions on regular expressions or environment variables? :) Going to wrap this up for now ... but again on Friday we'll be reviewing this *** Chris has quit IRC (QUIT: User exited) as i mentioned in the course material, there have been BOOKS written on regular expressions so to give it a one lesson treatment is taking a very brief review of them (^[:digit:]{3}\-[:digit:]{3}\-[:digit:]{4}$) TD, would this work for a phone number? don't need the \- in front of the dash OK, thought it might try to subtract it or something... but otherwise i think you have it :) it's not that bad, is it? hehe :) even so there is a good reason we waited until week 7 to get into these instead of week 1 or 2 hehe :) Not really.. Just makes you think kind of a necessity from here forward though :) You would have probably blown alot of folks out of the water with this in week 1 or 2 alrighty i'll catch you guys over in scriptschool if you want to chat further ... take care all and hope to see you all at Friday's radio program 1:30pm PST preshow starts ... :)) The biggest problem I see is rembering what everything stands for and what it does ;) *** CrEaToR-aWaY is now known as CrEaToR bye TD thanx =) * TDavid logs off Session Close: Tue Oct 17 13:15:22 2000