Posts that have the tag "php"
New Blog Update
I've been working on my new blog software for a few months now. I don't intend on adjusting the outward appearance of my blog in any appreciable way, so when I move from the old software to the new software, it should look the same. Rather, all of the changes I'm making are all on the back end of things.
I've been working to objectify my PHP code. Right now, my blog spans over 20 disparate files. There are a few files that are common to them all (similar to classes), but they're mostly for the more complex features. The problem I've been having is reconciling similar functionality and standardizing my coding practices. For instance, I recently spotted a bug in my site redirect script. Were my program stored in a few central classes, I would only have to modify a few portions of the code. However, because everything was apart, I had to modify 15-20 different files correcting the bug. Of course, even with classes, I may have to modify a fair amount of items. For instance, adding, editing and deleting information has a similar procedure with a different query string. With 4 different information classes with an add, edit and delete method in each, that's 12 instances of the exact same code. Making a method for the redundant code makes the code more succinct AND makes it easier to modify down the line.
Currently, I have information classes: my blog entries, comments, image info and image folders. I also have a class for database use, a utilities class, a user authentication class and an HTML class. So far, I've written most of the database and information classes. I need to fine tune and correct any logic errors and try to synchronize common class types. I've also finished writing my utility classes, as they were taken from the old utilities I used before.
The authentication and HTML classes will take a fair amount of time, but most of the logic and styles for each have already been written. I'll just need to slice them up and edit them to function correctly in a modular fashion.
If I were to give a percentage of completion, I'd say that I'm somewhere around 60%. I've completed a lot of the logic grunt work and I have a little left. Afterward, it will be about testing the applications to insure proper working order.
Posted on February 22, 2010 at 12:26 pm. 0 comments. Tags: website admin blog images programming php mysql database
MySQL objects
I was working on my blog objects organization paper this morning and I suddenly came to the realization that I was passing MySQL objects from the database class to the other classes in the program. I've been working rather hard to keep my classes as separate from each other as possible, so this came as a shock when I realized that I had been working completely counter to my goal.
So, I think I'll work on taking MySQL objects and transferring the data from the arrays that are returned and placing the data into a newly instantiated object. When I return a collection of items, I'll transfer them into an array of instantiated objects. Though, I need to insure that the data maintains its integrity. I wouldn't worry about Java doing such a thing, but PHP doesn't seem nearly as reliable...
Posted on January 20, 2010 at 08:09 am. 0 comments. Tags: php mysql objects
Tags
The tags functionality appears to have been non-function for quite a while. A while ago I changed a bunch of my functions around to make the names clearer and follow certain programming conventions (such as the camel hump naming scheme). However, I neglected to change the function names in the tags file and because of this, the function wasn't working at all. The odd thing is that there were no errors to indicate WHY it wasn't working. After some judicious commenting of functions, I figured out which function was the culprit. This problem has highlighted my need to separate my functions and code into more manageable chunks with less disparities.
Posted on January 18, 2010 at 10:50 am. 0 comments. Tags: code php objects admin
Overloading PHP functions and methods
In a nutshell, it's not possible.
PHP only allows one function or method with a name to exist per class and only one constructor per class. Originally, I was going to write a class called "Entry" which had two constructors. One constructor would receive arguments for all of the attributes of the object and a second constructor would receive an id number as an argument and retrieve the attributes from the database. Now, I'll have to create an empty object and just call a method that does what I want e.g.: Retrieving the data from the database and filling in all of the attributes I give it.
Now, a "magic" method exists represented by "__call" with two passed value: $name and "arguments. The first argument, $name, is the name of the method that you just called. $arguments is an array of all the values you passed to the method.
So if I have an object called "$car" and I called a function like so: $car->conversion($value1, $value2), the $name variable has the name of the method I called ("conversion") and an array containing $value1 and $value2.
Posted on January 13, 2010 at 11:57 am. 0 comments. Tags: php admin
No real updates
I've been slogging away at a description of objects for my blog. I anticipate it will be somewhere around 5-6 pages long and will take a bit of time to organize before I can finally start coding. The good thing is that I already have the logic figured out in my current code (which is mostly imperative). The hard part is figuring out how the objects should interact with each other. I'll try to enumerate everything a little later.
Posted on January 11, 2010 at 02:45 pm. 0 comments. Tags: admin php blog objects website
Java
I'm about half way through Beginning Java Objects, by Jacquie Barker. This is a few months after finishing Murach's Java SE 6. The first portion of the book dealt with syntax and I feel as though I had a pretty decent grasp of the syntax already, so I was able to go through that portion of the book quickly and easily. The second section was about object modeling for a project. This portion of the book I glossed over and didn't really bother reading very in-depth. However, I started to realize the importance of modeling objects.
I've been struggling with direction in modeling objects for legal software I want to design as well as modeling objects for my blog, which I want to fully revamp into OO design. Thus, I think it would be very beneficial for me to re-read this whole modeling section before continuing on to the third section of the book.
However, before I even go back and read that, I decided to put Object modeling on the back burner for a little bit so that I could start a new book: TCP/IP sockets in Java by Kenneth Calvert. Before I can fully realize how the objects in my legal software can work, I want to become knowledgeable of Network programming so that I know which objects should do what and be more qualified to program the legal software.
As for my PHP objects, I'm finding it difficult to separate the procedural issues from abstract issues. That is to say, I want to try to abstract what my blog does, but I find the procedure creeping into my abstract description. Nonetheless, I'll try writing it out further in the hopes that I can feel my way through this.
Posted on December 21, 2009 at 10:07 am. 0 comments. Tags: Java admin php development dev
Objectifying my Code
I'm considering objectifying my PHP code on my website. Right now, my code is mostly procedural. I knew what I wanted to do with my code and I did it from beginning to end. For the most part, this has been just fine.
However, as of late, I've been tweaking a large chunk of my code to optimize the way it looks AND to minimize superfluous commands. The problem I ran into is that I was starting to create functions that were common to a LOT of my code. At first, I wanted to merely create a utilities file that I would include. But, now I'm thinking that creating a few objects and classes would go even further to helping me out with the output of my data.
Posted on December 04, 2009 at 11:58 am. 0 comments. Tags: admin php objects OOP
Website Overhaul
I've been in the process of overhauling the code of my website. I'm cleaning up a LOT of my code to make it more readable and condensed. I'm also trying to remove redundant code through the use of functions.
I've also removed MANY bugs that I found after reviewing my code, especially a few that concern data sanitization.
Finally, I'm rethinking my Image Gallery program and scripts. Namely, I'm removing some of the superfluous code I'm using that "pretifies" the data. For instance, I play with the manufacturer and model names to make them look better. However, I'm going to leave them raw. I've changed the look of the image galleries to reflect this change to raw data. I'm also going to include titles. A field will be available for a user to input a title of their photo. If the user doesn't fill in the title, the original image file name will be used as the title.
Posted on November 30, 2009 at 08:03 am. 0 comments. Tags: admin exif image program php javascript
Search Function
I'm going to add a search function to my blog. Initially, I'm going to give the ability to search only tags. The tags represent a far smaller amount of data and an inefficient search engine won't be too much of a bear on my system (as far as I can tell thus far). If it does become a problem due to abuse, I may have to disable the search function or design restrictions (probably based on IP) to limit the amount of searches on makes in a set amount of time.
I feel that I'll need to research searches to see if there are methods that are more efficient than merely passing sanitized terms to SQL for search.
Posted on October 01, 2009 at 07:19 pm. 0 comments. Tags: website php sql admin search
Cat Shelter Software
I've been volunteering at a local cat shelter near where I live. Mostly I've been helping at events at a farmer's market where I stand around at a table, talk with patrons and encourage people to take a look at a cat or donate and just talk to them about their pets.
I also used to help with data entry. Though, I've become increasing frustrated with the software used. So much so, that I want to develop an online database for all of the data. I already have experience in developing front end, web-based data pages. The biggest hurdle, right now, is database construction. The medical information is so varied, that producing a single table or a set of tables is difficult. So, I have to extract the information from the shelter manager/owner...but, that's difficult because she's so busy. So, before I talk with her, I just have to do what I can for now and move on afterward when I can talk to her.
Though, I've also been thinking about developing law administration software. Having worked in the legal field for several years, I think I have the knowledge to start writing my own, custom software to keep track of what I do now. Initially, it'll have to be web-based, but I hope to eventually learn network programming, allowing me to communicate within a network and maybe even remotely. Though, before I even start, I'll need to have a look around and see what else is out there and how they work.
Posted on August 10, 2009 at 11:11 am. 0 comments. Tags: software cat shelter law software database php java
Site Updates
Holy Crap, the code for my site was far worse than I expected. I'm currently reviewing the entirety of my website's pages. There are quite a few deficiencies in the logic in some of my pages. Moreover, remnants of debugging exist. Finally, I was far too concerned about removing any bit of javascript from my page that I made some rather roundabout coding when Javascript redirects would have been better. I'm also going through the code attempting to comment the code so that it's more readable.
I'm also pulling apart the code attempting to separate and abstract some of the functionality, such as page redirects, which may be better off as a function.
Moreover, I also learned more about cookies. Turns out that when you initialize a cookie, you cannot use that cookie on the same page. My new code would authorize if it could read all cookies that I set for authorization and de-authorize if it could not read them. This would merely be a variable that would enable certain features on the page for authorized users. So, my page would tell me that I wasn't correctly logged on, but going to any new page would show that I was, in fact, logged on. What I found out was that my old setup would authorize if the cookies were correct but would NOT de-authorize if the cookies were incorrect. This, to me, was rather sloppy. So, I changed this aspect, but it's going to necessitate an extra step in logging in so that the login pages reads correctly.
In the end, this will take a few days to be put up.
Posted on June 01, 2009 at 10:17 am. 0 comments. Tags: dev php javascript website admin
authentication idea
I've been contemplating a new method of authentication. Right now, the authentication is a mass of spaghetti code and hashes of hashes of hashes. Despite the obfuscation of information, there are some worrying problems. Namely, information stored on the client side is static. A session ID changes from time to time, but this could potentially create a problem and may make it easy to deconstruct the authentication.
I've decided to simplify the authentication process and make it more difficult to deconstruct or spoof information. The SQL tables obviously hold hashes of passwords to protect the password information. I've also constructed the website to hash the password client-side so that when information is sent as plain text, no person can grab the password information, only the hash information.
My current idea is to create a table of 500-1000 entries. Each entry will contain a random number of 8 digits or longer. When a password and username are sent to the server, they are checked against the username and hash already stored in the SQL tables. When the username and password are authenticated the first time, a random key will be chosen from the table of random numbers. The random number from the random key will be used as a salt on the end of the password hash. A new hash will be created from this string.
Afterward, 3 cookies will be created on the client's computer.
A) The username
B) The random number key
C) The new hash
When the server attempts to authenticate, all 3 pieces of data will be sent to the server. The password hash of the username will be retrieved as well as the random number from the key. The random number will be salted on the end of the password hash and a new hash will be created. This hash will be compared to the hash stored in a cookie. If everything is correct, they should match. Otherwise, the random number has changed, or a spoof has been thwarted.
This, of course, doesn't solve the problem of the initial contact with the server as nothing is encrypted beyond a hash, but it makes sure that everything after the initial contact isn't in plain text or easily readable.
Posted on May 26, 2009 at 12:42 pm. 0 comments. Tags: hash sha1 website php mysql sql password username administration
Site
This week, I'm going to make some updates to the site. Namely, I'm going to revamp the security of the log in feature as well as adjusting the log in time from 1 hour to multiple hours. I'm also going to add a few features, such as a preview pane when adding a new post.
I'm also going to do a slight bit more research over at flickr and finalize my SQL table structure for my image gallery.
Posted on May 26, 2009 at 07:54 am. 0 comments. Tags: site administration php SQL mysql
Update
I recently wrote a script for my server that uploads a file. At its base is a HTML form that allows a user to choose a file and upload the file. From there, PHP will catch the file, move the file to a temporary upload directory and output information on the file. That, in and of itself, is neither difficult nor complex. In fact, it took only about 20 minutes to get an idea of what I need to do, edit the php.ini file to allow for larger file uploads and so forth.
The problem, however, is how browsers treat file uploads. When you upload a file using plain HTML, the browser will sit there uploading with a blank screen. Once the file is uploaded, then the next page loads and renders. To me, that's intolerable. If there's a problem with the upload, or it's going oppressively slow, you won't be able to figure out why. Thus, feedback was necessary for an upload script to function well enough.
Initially, I was looking at writing a CGI/PERL script or learning enough java to write a scriplet to facilitate the upload bar. But, the amount of time needed to figure that out was way too long. Though, I found out that PHP did have some function called APC that caches data and allows me to retrieve it. IBM wrote an article on APC usage that helped me out. I found that a lot of people had trouble getting apc_fetch to work and that it would return "false" when uploading data. I found that you needed to add "apc.rfc1867 = on" to your php.ini file. Afterward, it functioned correctly.
The page itself is a form with two buttons and a text bar. One button to browse for a file and one to submit. I have two Iframes on this page, which both start blank. The left Iframe is where the uploaded data is sent. So that frame will sit there loading. When the file is uploaded, the data on the file is displayed. The right Iframe is where the progress is shown. A Javascript function was written to wait 1 second (to make sure the cache had enough time to be reset) and then load the progress bar. The script reads the cache file and retrieves the amount of data sent and amount received and produces a percentage. The bar itself is a div box that's 100 pixels wide and 20 pixels tall that's white with a 1 pixel black border. A second div box is inside with a width that's the same as the percentage complete. So it extends as time goes on. Another javascript function is written to reload the progress page every half second until progress is equal to 100.
What this means, to me, is that I'll be able to write my pages and scripts for uploading, converting, storing and showing my photos for my website.
