Feeds:
Posts
Comments

Archive for the ‘Coding’ Category

PHP + $$ = <3


I’ve been a little sparse with the posts lately, for which I apologize to any followers I might actually have. (No one? Ahh, ok then.) I actually had a perfectly good excuse to be busy – I finally landed my first paid web programming contract.

Now, don’t let the pretty image fool you – all I was paid for was the back end stuff. The CSS template I tossed together looks nothing like the final version, which is being done by somebody else. Still, a portfolio piece has to catch the eye, or what’s the point? Since the final website isn’t up yet, I’ve left the test site up on my server if anyone wants to take a look. Once the final one goes live, my test version comes down, so log in, take a look, add some stuff if you want to, but don’t expect it to be there a month from now.

Now, on to the stuff I learned. This was the first time I really had to worry about security and user input. My previous sites were all completely owner created content, so as long as all the punctuation was there, they didn’t have to worry about about hackers getting at their code from the front end. For this one, pretty much all content is user generated, so I pulled out all the stops. We’ve got variables being passed all over the place that can be spoofed, input fields to check and recheck but keep intact for display, and then there’s the little things that keep users from messing with each others’ content.

It was also my first time implementing a drupal-style index.php file, where pretty much all of the actual page content is served by the main page via includes and if statements. There were a lot of decisions to make, even after everything was paid for and I was tossing on some quick presentation CSS. (I especially like how the category divs look. Gotta remember that one.)

I also learned some things about the way I manage my time, once the 40 hour budget was slashed to 30 and then to 20 hours. I found this great little punch clock that let me clock out in a hurry if the kids were pulling each others’ hair out, etcetera. That’s my only real regret – not having enough time to finish the project. Still, I got some great things finished in the limited time I had, and eventually they’ll be done with the presentation stuff and need my help again.

Advertisements

Read Full Post »

Well, that was fun. I wouldn’t say I’d mastered PHP yet, by far, but now I’ve got a fair idea of its capabilities and a good collection of stock code snippets to play with. Now that I’ve spent months crawling the web for some tips on building a website with PHP, I’ve decided to put together the PHP tutorial I wished I’d had at the beginning. I’ve skipped over the bare basics in favor of explaining each line of code one piece at a time, and tried to write with the assumption that the reader doesn’t have a background in programming beside html itself. (I think I might have to build an html and css tutorial later – it was fun).

The tutorial covers all the topics I thought were vital to my website project. I started out with a basic run-through of what PHP can do and what you have to know/have before you can use it. Then I went right in to the meat and potatoes, but in the order I wish I’d learned it, rather than in the order I did. I started with using includes – writing part of your page code in a separate file for ease of editing later – then moved on the the tough stuff – databases. Admittedly, I have no idea how any of the other databases might differ from MySQL, but since that’s not what the tutorial is about, anyone using a different one will have to debug things on their own (what better way to learn, after all!)

I focused a good bit of time on the part that took me the longest to get working – that is, generating dynamic URLs with a query string. I completely skipped the ‘try this example’ stuff – there’s plenty of those on w3schools, and they didn’t really help me. Instead I used an approach I learned in one of my textbooks – explaining lines of code one piece at a time with helpful examples and a personal style. I’ve also included real working examples of code and suggestions for what uses to put them to. The goal is to get the reader from knowing nothing to understanding PHP in 4,000 words or fewer. I’d appreciate any feedback, either here in the comments or on the lens itself (backlinks welcome – one per comment please) from anyone interested in PHP on how well it accomplishes this goal.

As a little extra tidbit, I’ve included some tips on converting dynamic URLs to static ones. There seem to be several different methods out there, many of them far too complicated for a beginner to try, so I snagged a pair of the better ones and did a little how-to for ‘dessert’. Enjoy!

Read Full Post »

Back in the Habit

Lironah Daviau scripting a carousel Who’d have thought a week ago that I’d be back in Second Life again, scripting in lsl? Certainly not me. Today’s project is a rotating, bobbing carousel horse.

All I can say is that the Java textbook I’ve been reading has gotten to me. About 36 hours ago I watched my first lsl tutorial and shortly thereafter coded a clock with moving hands, mostly as per the lesson. I had to tweak it a little because he used a square clock, and I hate square clocks. It took some juggling to get the hands moving correctly on a rotated cylinder prim instead of a boring old wooden block. I even found a most awesome wolf clock texture in my freebies.

After my success with the clock, I must have been suffering from sleep-deprivation induced insanity, because I decided to keep going. I found an old, forgotten project in my inventory – a carousel model that…well, didn’t work so well. At a tip from my dear friend Ingeborg, I stepped over to the scripting college and took notes until 2am.

When I woke up, the bug was still with me. I dug out my notes and by lunchtime I had the bobbing problem pretty much licked. Crazy, huh? Two days ago I couldn’t so much as script a “Hello Avatar”. After lunch it was on to building a prim carousel horse. Pink with blue hair seemed appropriate.

Then, as dinnertime rolled around, it occurred to me that if I was going to make these and sell them in Second Life, I was going to need some appropriately candy-flavored music to play while the horses turned. So what did I do? Did I go digging through my inventory for something cute enough? Did I spend hours on a fruitless search through SL or the internet to find some nearly-free sound bytes?

Heck no. This called for some exercise of my new free trial midi writing software. An hour later, I’d turned a snippet of tune into 48 seconds of loopable sugary goodness which you can feel free to listen to. I call it Pink Carousel. Witty, I know.

(For anyone curious, my Second Life name is Lironah Daviau.)

Read Full Post »

Did I say easy?

Oh, goodness.

What is it, 3 days since I cracked the code of php? 4? Well, those last 4 days have been spent trying to expand upon my previous coding project and draw different products from the database. I hit a block when it came to drawing a single line from the database, and have been playing the elimination game ever since, trying to figure out what part of my code has been corrupted. The first 3 days gave me a pretty good run of the basics, and now I’m pretty sure I can spot most major syntax errors in the code I’ll be using. Finally, however, I discovered that my real problem was coming from an inherited .htaccess file in my root directory. (Burn you, FatCow!) Argh. So by the time I got that figured out, I’d apparently started using $ in my urls instead of ?, and that just doesn’t work. Hunting down that one took a good 2 hours of my day today. Now, however, my queries work as they should, and once I add in a little rewrite code to make those urls look static (yeah, you can laugh at me when that takes me a week to figure out), I can move on to coding an input page for my father-in-law to add products from. But for now…it’s quitting time.

Read Full Post »

Victory At Last!

I’ve been trying to wrap my brain around php for the longest time, and tonight everything finally clicked into place.

Ever since the first time I looked at Drupal’s source code and realized that I had yet another programming language to worry about, I’ve been trying to study the basics at W3Schools.  I must say, compared to their html and css tutorials, the php one leaves something to be desired.  Still, I persevered, and with some judicious use of google search I managed to find the answers to the basic questions it left unanswered – namely, how to use the include command and how to use it to interface with mysql.

Even with the most helpful tutorial from Codewalkers, it took a little bit of time for the fundamentals to sink in.  Finally the third time I looked at it (about 5 hours ago now) I started to understand which pieces did what and how to interpret the code I was looking at.  After that it was much easier to find what I was looking for.

Next thing I did was build a database (I used the shortcut built into my web host’s control panel – no use taking chances where a database is concerned) and started piling variables into it.  I started with a simple test to see if I could replace my navigation menu with a dynamically created one.  It worked!

My next step was to fill my husband’s webpage template with php variables drawn from the database.  I must say, I have never had a such smooth and easy to debug coding experience.  After fixing one small typo, the only thing I had to do was a teeny little math function and I was done!  If only Javascript were that easy.

Read Full Post »