Wednesday, April 25

Wasting time is my expertise

I didn't really do anything today, so I have nothing interesting to post. Darn.

Make sure you're consistent with your variables. I mean, call them with the name you defined them with, or else they won't work. Duh.

Lack of focus seems to be my problem today....

Tuesday, April 24

PEAR Mail Revisited

I FINALLY got somewhere to relay my mail. (That was the biggest hassle ever. No one wanted to do it because it wasn't "right" due to departmental issues. My issue was that it's for TESTING. What's not right about it, I'll be using it for a month, maybe 2 at most. I don't need an inbox, I don't need anything but a machine to relay my email.) Anyway, I finally got it and then realized my mail function didn't have the "send" part. That's kind of important. I added that to the post about this before too.

I did my mail test function and got errors. It was missing some files. Hmm, that's weird. I got this from PEAR, why would it be missing files. Well, what they fail to inform you when you download mail (either from the website or by doing "pear install mail" from the command line) is that you need to get Net_SMTP and Net_Socket as well. Once you've got those files, it's probably just easiest to put them in the locations they want. That means the file tree will be like:

Mail -
mail.php
null.php
RFC822.php
sendmail.php
smtp.php
Net -
SMTP.php
Net -
Socket.php

Monday, April 23

using PEAR Date with MySQL

So today, my small realization cost me some work, but simplicity in the result. I discovered that if you use the PEAR function Date(), you can correspond that directly to a MySQL database. Previously, I was using Date to format the date how I wanted it, but then using a UNIX timestamp to make sure the dates appeared in order. All I really needed to do was have the field type for the MySQL database be datetime. The output for Date() is the current date and time in the format YYYY-MM-DD HH:MM:SS, which is the MySQL format for datetime. I ran into this little problem. Before sticking a date into the database, you need to convert it into a string. I was trying to do:

$date = new Date();
and just inserting that... I'd get the error Catchable fatal error: Object of class Date could not be converted to string in...

What I really needed to do was:
$d = new Date();
$date = $d->getDate();
Which converts the output to a string before putting it into the database. It worked much better. So the next really cool thing I discovered is, once that's in the database, if you want to call out anything with a date after today (say for some sort of due dates or schedule) you can use the MySQL function date(). Such as:
//get all fields from table sched where date is after now
mysql_query("SELECT * FROM sched WHERE date>now()");
That saves a lot of trouble.

Thursday, April 19

Vista Hates Windows Domain

I have a Vista box I installed a while back. I put it on the domain and everything was all fine. Well, one day, I noticed the box wasn't named what it was supposed to be and being kind of OC about that, I changed the name. After I rebooted, the box had removed itself from the domain. hmm. I put it back on. I logged on with my domain credentials and all was great. Till I rebooted again. Once again, removed. It wouldn't let me put it on again because the computer was still in the AD list, so I renamed it. Then rebooted. Then put it back on the domain. Logged in. Rebooted (to test it)... BAM! off again. I've even tried putting it on a different domain it's never been on. Still removes after reboot. Haven't found the cause yet, but I think that's really weird.
-------
Update:
I think the box isn't really removing itself from the domain. While logged on, it has all the resources and otherwise acts like it's on the domain. The real problem seems to be it doesn't allow domain users to log on. I don't get an option to switch users on the login screen (there is one local user), therefore, there is no box in which to submit my domain credentials. I thought I found people with the problem, but they were just confused because you have to now use the format domain\user or user@domain.

Wednesday, April 18

PEAR Mail

So I've been needing to set up something so I can send automated emails from a website.

So... I created a simple PEAR Mail script, just to try it out. The script resulted in success, but I never received any emails. I changed the type to mail, which is just php's mail() function to see what was up and the error I got was SMTP server response: 554 Relay rejected for policy reasons... which makes sense, since I'm off campus working on a development server. I just wonder why the smtp mail type didn't tell me the error too. It would have been nice. Just to make this post look longer than it is, here's the code:

require_once 'Mail.php';

$recipients = 'me@example.com';

$params['host'] = 'smtp.server.com';
$params['auth'] = TRUE;
$params['username'] = 'email@example.com';
$params['password'] = 'passw0rd';

$headers['From'] = 'email@eaxmple.com';
$headers['To'] = 'me@example.com';
$headers['Subject'] = 'SMTP Test';

$body = 'test message';

$mail_object =&Mail::factory('smtp', $params);
$mail = $mail_object->send($recipients, $headers, $body);
if(PEAR::isError($mail)){
echo($mail->getMessage());
}else{
echo("success");
}

Tuesday, April 17

Working ZipArchive

Ok, I finally got it and feel really dumb now. It turned out to be the bane of my existence.... permissions. What would make me thing the IUSR_SERVERNAME account would only need write permissions. To change a file, of course they would need modify permissions too! DUH!

I figured a lot of other things out along the way too. Like: ZipArchive likes relative, not absolute paths. I had to rewrite some stuff because of that. I had been using 7za.exe, but wanted to start using the php_zip.dll since I upgraded to php5.

So here's my code for pulling file names from a database and stuffing them into a zip. I turned it into a function that throws back the zip file name. These are zips of the files in a bunch of teachers' lesson plans.

function zipper($id){
include 'db.php';
$query = mysql_query("select distinct path from files where id=".$id."");
$query2 = mysql_query("select title from lessons where lesson_id=".$id."");
$row = mysql_fetch_assoc($query2);
$zipfile = str_replace(" ", "", $row['title']).".zip";
$filename = "teacherfiles/zips/$zipfile";
//create archive
$zip = new ZipArchive();
if($zip->open($filename, ZIPARCHIVE::CREATE)!=TRUE){
exit("Cannot open $filename");
}

while($result = mysql_fetch_assoc($query)){
$path = str_replace("%20"," ",str_replace("&","&",$result['path']));
$zip->addFile($path);
}
$zip->close();

return $filename;
}

What happens is I call a popup window, which calls the function, makes the zip, then uses a meta-redirect to the created file to prompt a download. After 30 seconds, the window redirects to a page that deletes the file and closes the window almost immediately. It's pretty cool.

Monday, April 16

ZipArchive

Man, I'm trying to get this to work, but I'm not having any luck at all. It's driving me nuts!!

I'll post a solution when I get it. I've got my WIMP with php 5.2.1 and zlib 1.2.3, using the sample code from php.net

It's supposed to create a file called test112.zip, but instead I'm ending up with test112.zip.a03600 and another one called test112.zip.b03600. It's time to go home now, but I'll figure this out tomorrow.

--------------------------------------------------
Well, I'm still working on this. I'm super confused because I'm still ending up with those temporary files. I moved the script to an area where I know IUSR_SERVERNAME is allowed write permissions, but that didn't help.

I tried making .gz files just in case zlib really doesn't work with .zip, but those didn't work either.

If I use AddFromString, I can rename the files ending in zip.a03600 (or whatever number it happens to be) and then I can extract it, which is saying to me a rename error. BUT, if I use AddFile instead, no files are added and the zip isn't even created.

I tried going through the list of errors and seeing which ones I get, but it ends up being most of them. I couldn't find a way to have it report which error it's getting, so I wrote a bunch of ifs. Turns out that wasn't the best option, since all but ZipArchive::ER_OK resulted in true.

I'm still workin on it, but interrupted by people who can't print.... ._.

Saturday, April 14

What a WIMP!

Oops, forgot to post something yesterday. I'll try to put up something later today, but in the mean time, a random observation.

We've all heard of a LAMP (Linux Apache MySQL PHP) server... well, I'm not sure if this term has been highly spread around, but I'm running a WIMP!!! (Windows IIS MySQL PHP)

In case anyone wonders, I did not get to choose the webserver and if I had a choice, I would never use Windows as a webserver again. I've had experience with both now, and as far as I can tell, you're better off running a LAMP than a WIMP. Even a WAMP isn't so good as Apache has no real advantages on a Windows box over IIS. Actually, it's probably worse. There are a lot less things you can do since it's not Microsoft integrated software.

Just my 2c...

Thursday, April 12

My Google Maps

If you haven't noticed, Google maps has added "My Maps" to its page. This allows you to make and save Google Maps instead of having to use some other website like mapbuilder.net. You can even export your maps in KML format for use in Google Earth. I made a map, but it's not very exciting... Still, if you like to watch cars drive by, here it is: MATC ITS Cameras - Omaha, NE.

Wednesday, April 11

First Post Ever

This will be my log of discoveries and problems in web development and systems administration. I will try to post one thing every day in the hopes that someday someone will find it helpful. Hopefully, soon I'll change this template thingy.

Happy Coding!