PHP questions, your knowledge would be appreciated

Paithar

[H]ard|Gawd
Joined
Jul 17, 2003
Messages
1,049
Here's the deal. I started working for this small company about two months or so ago. I've been a programmer before but never for web page type stuff. So, this company hired me to learn PHP and mySQL so that I could do enhancements, fixes and what not to a series of web pages that are client specific. Little did I know what I was getting myself into.

When I first started I learned that the existing web pages were put together quickly by people that also at the time did not know PHP and mySQL so they learned what they needed to in order to get the website up and running and since then only learned what they needed to for any additions and fixes that came up. When I heard this I got worried because in my experience with other languages when this happens the code is barely readable and a pain in the ass to maintain. As I feared this was no exception.

Anyway, I bought a book about PHP4 and PHP5 and mySQL5 and proceeded to learn. I was then given a task to add a couple pages. A simple form with a user validation page that would then send the info via email to a certain person here at work. I set it up and tested it on my own local pc and once it worked I had them move it to our web server for testing. It immediately broke. It was then that I found out that they are running something like PHP3 and I don't know what old version of mySQL. So now I have to unlearn some of the things I've learned that are PHP4 and 5 specific and figure out how to do it in version 3.

So after that long rant here's my questions. First, is there any reason not to switch to a newer version of PHP and mySQL other than the fact that some of the web pages will have to be fixed? I mean security issues and what not are actually better in the newer versions correct? They could be using session management and I told them about that but they have this idea that session management in the newer versions isn't very secure and that anyone can simply break into their system then.

Also, they currently write every single page using printf statements that print out html tables and nested tables. This makes for extremely unreadable code and hard to maintain code. The couple of pages I wrote basically keep everything in html except what needs to be output using php. As I'm still learning CSS I haven't tried to change it to not use html tables so that's a pain but since I can indent and otherwise format my code it's at least easier to read yet they say that it's better if I use printf statements like them.

If I can't change their minds on some of these things I guess I'll just deal until I learn php and mysql better and then can get a different job. What sucks is I really like the company and the people here and I'm extremely grateful that they've given me this opportunity to learn this stuff on-the-job because no place else I've ever been as a programmer would let me learn a new language just starting out.
 
using php 3 instead of php 4 is like using windows 3.1 instead of xp. using php 5 might be like using vista beta, though php 5 is official now, not in beta, i don't think it's necessary to use php 5 at the moment.

i believe the most recent stable version of mysql is 4.0 or 4.1, i can't remember. same thing here.

i can't speak directly about security with php since i don't know specifics, but the newer version is bound to be more secure than the older version
maybe http://us3.php.net/security can give some insight

using printf for everything = very stupid, i can't begin to imagine why the person who wrote it originally would do that. printf has its uses, but its not some sort of magical catchall print thing

anyway, upgrading php and mysql is definately what you want to try to do.
 
Those were my thoughts about everything. Now if I can just come up with a way to convince them to upgrade! :)

I have a feeling though, that I'll have to secretly convert the whole website to use the newer versions and test it extensively on my own time and my own pc. Then once I've got everything working, show it to my supervisor and see what he says. Unfortunately converting the whole website won't be a quick and easy thing since the whole site has been written with those printf statements and there's something like 50 different pages. Most are only little apps that query the database and produce a report but still they would need a little converting.

Oh well. I guess I'd better started. :rolleyes: Thankfully I already have a current copy of the whole website on my personal laptop. When I first started here they didn't have a pc for me so I volunteered to bring my laptop in and use it for a couple of weeks.
 
In fact tell them to upgrade to the latest STABLE version of php (www.php.net) as the version you have is outdated and could cause a bigger problem than trying to convert crappy code.
 
stable is definately the way to go...

also, you made mention of nested tables being hard to read and whatnot... without a doubt its one of the most difficult things to navigate through, for that i recommend a good text editor... ie "pspad" ... a great editor.

if you've done little programming this is what i like to do (replace the dots with tabs)


<table>
....<tr>
........<td>some stuff
........</td>
....</tr>
</table>

that way you can lineup where stuff is supposed to be, and make sure your dynamic tables are matching up properly... i'm actually working on a script that will let you paste in any dynamically generated html and it will tell you if every <table> has a </table>, <td> and </td>, etc...
 
Before you do anything, I'd also recommend getting your company to upgrade PHP and mySQL versions. PHP 4.3.x is the one used on the majority of servers in the world (some people use PHP5, I don't since I haven't bothered to learn the new stuff ;) ), and MySQL's latest is 4.1 (5.0 is in dev, but I wouldn't recommend using it in a real server). Get with the times! :p

As for the tables thing - if it's tabular data, leave it alone, that's what tables are for. If it's layout type stuff and you're willing to change it to full CSS, that'd be nice, probably easier to maintain it that way.

You can also use PHP includes for files to keep things orderly (like have a file for a header, footer, and content and on the pages just include them and that's it). Includes makes updating a site so much easier.

I haven't done much with sessions though, I'm still using cookies (though I'm trying to change my site to use sessions for things like custom CSS settings). Good luck!
 
Back
Top