Forum Moderators: coopster

Message Too Old, No Replies

Macromedia Dreamweaver PHP Code robustness

         

juliebelle

12:42 pm on Nov 11, 2004 (gmt 0)

10+ Year Member



I have just starting using PHP for developing a website. I am using macromedia dreamweaver in the process. Macromedia does generate a lot of code for you. I created a login/authorisation page in a matter of seconds.

My concern is how robust is the code generated is. Any one has experince with this? I am using sessions to handle login authentication. I also checked my php parser settings and Global Variables are off.

The code generated is not using any globals cause its working fine.

ergophobe

4:47 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've only seen it in code that I've been given by someone else, so I can't really say. My impression is that the code is messy and often uses deprecated features (e.g. $HTTP_POST_VARS).

Like I say, I have very very little experience with it though, so hopefully someone will chime in. If not, you might try over at the Editors forum.

Tom

juliebelle

12:01 am on Nov 13, 2004 (gmt 0)

10+ Year Member



thanks for your reply. i am using the MX2004 version and it does not seem to be using old tags. I am getting to understand most of the code generated. I got particularly got stuck with this snippet however...

$query_getMemInfo = sprintf("SELECT * FROM mem_info WHERE id = %s", $colname_getMemInfo);

what does the %s represent here? any ideas.

coopster

12:20 am on Nov 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's part of the conversion specification:

sprintf [php.net]

ergophobe

1:39 am on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Basically, the % says it's a special thing and the "s" says it's a string. It's taking the string variable after the comma and sliding its value in in place of the %s

when did coopster get so terse - I thought that was my job ;-)

mincklerstraat

10:25 am on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll also find a lot of great free pre-packaged scripts, classes and functions which will help you do a lot of groovy things in just a few minutes. In the long run, just modifying these with some of your own code is likely to be a timesaver compared with creating code with dreamweaver. You'll understand the code better and it will be better maintainable and modifyable.

minck is a distant admirer of terse

coopster

4:37 pm on Nov 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Ouch! My responses are never meant to be terse, so I hope it wasn't taken that way!

The italics were to emphasize the nomenclature and the simple link was a point of reference. Sorry if it seemed short, I was rushing to get out of the office and didn't want to leave juliebelle without an answer.

I'll terse you, mister ergophobe .... ;-)

juliebelle

11:13 pm on Nov 13, 2004 (gmt 0)

10+ Year Member



mincklerstraat.... i like the idea of modifying scripts and using them instead of generating with dreamweaver. Where can i find good and modifiable scripts out there? What books you recommend for learning PHP.

I need books that teach good procedured to cater for code reusability. I think that is very important, especially with PHP 5 being fully object oriented. Any suggestions?...

Thanks very much

Julie

jatar_k

1:56 am on Nov 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld juliebelle,

try this thread for some ideas
Learning PHP - Books, Tutorials and Online Resources [webmasterworld.com]

ergophobe

11:29 pm on Nov 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Juliebelle,

You can get all kinds of scripts off the net for all purposes, but many of them are not good to learn from, so be a little careful of what you take as your model. I suppose that's obvious. If you're just new to PHP rather than new to programming in general, then I think modifying existing scripts is a good way to learn syntax. Learning style is another matter. I don't know of any really good PHP-oriented resources for that.

As for being terse...

Coop, that wasn't meant as a bad thing! According to Meriam-Webster's:

terse (adj)
1 : smoothly elegant : polished
2 : devoid of superfluity.
synonyms: see concise

Hardly a reproach!

Tom

mincklerstraat

10:15 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Julibelle, this is definitely the right way to get started well and save yourself time in the future - getting a book, reading it on paper at a leisurely pace a distance from your computer, and checking out code that people have already written. The last book I've seen that I really liked was Rasmus Lehrdorf's book on PHP available from O'Reilly - this isn't about PHP 5, but it will give you an introduction to object-oriented coding. Harry Fuecks writes very well, and he has a two-volume anthology that Sitepoint puts out; the sample chapters look very good, but Lehrdorf's might be better for a beginner, since Harry is pretty quick in diving into more advanced topics.

Code re-usability is important indeed; just remember this fact, keep it in you mind as one of the issues of coding, but don't let the gurus scare you about what the golden ideal of coding is; most of this comes from noxious reactions to really, really badly written code (one thing I really like about this forum: no gurus who take pleasure in verbal spankings). If you start out realizing that code re-usability is an essential value in coding, as you already do, you won't write utt-bugly code, and will have time later to get down to dotting your i's and crossing your t's when it comes to re-usability and elegance. First you just have to have a good understanding of how stuff fits together. So first get a good grasp of coding - for style, I'd say learn from the beginning to avoid quoting strings in double quotes and start out with single quotes and concatenators

('.' - $color = 'yellow'; $destination = 'home'; $sentence = 'the '.$color.'flew '.$destinaton';
instead of
$sentence = "the $color bird flew $destination";)
. Before you try to understand OO, classes, methods, etc., make sure you have got a good understanding of multiple-dimension arrays.

I've often wondered what scripts would be the best for newbies to get a grasp of what PHP is actually doing, and unfortunately couldn't really name any - most seasoned PHP coders will be working on their own scripts, and these are often long and gnarly, even if written well. I would indeed like to hear from others if they know of good scripts for recommending to beginners.

Code that Dreamweaver produces is probably not a good style example, either in HTML or in PHP; the example you gave, for example, isn't very good - '*' is an inefficient way of querying a database (although very easy - use it when you begin learning, but replace later), and using sprintf in that way may have some value in security for auto-generated scripts, but isn't good for code you write by hand - too confusing, also a bit less efficient - would be better done otherwise.

juliebelle

6:59 pm on Nov 15, 2004 (gmt 0)

10+ Year Member



thanks ergo for your advice. I got your point. i know you can read many books and tutorials about good programming techniques but at the end its up to the individual to find a style that is good for her and use it, PHP gives you lots of stuff to work with.

cheers :)

Julie

BTW. I was wondering about sessions. I read that session_start()must be declared on each file that must be 'protected' using sessions. is that true or will it start a new session each time session_start() is called.

I need a way to create a robust user authentication system where not more that one user can log-in with one account. any tips. I thought about creating another session variable and use it as a flag to check the status of the user. when the user logs in, the flag is set to true, when he logs out back to false. while the flag is set to true, no one else can log-in. I think i would need to write the flag in the user database however....

just an idea. Any opinions?

mincklerstraat

10:51 am on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to do
session_start()
before your session variables are available. This is a misleading-sounding function because it only 'starts' a new session when it can't find a valid session to continue. If there's a session that's still fresh that it can find, it will use that one.

Yes, you'll have to have a db entry in addition to sessions to allow usernames to be logged in only once at any time - sessions don't know anything about other existing sessions.

I wish you lots of success with your project. If you have further questions along these lines (sessions), I'd suggest you start a fresh thread - it's good to start new threads with new questions.

juliebelle

5:55 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



i have started an new thread about session. those interested please go to [webmasterworld.com...]

BTW. ergo. Thanks for the information. ....so i was on the right track :-)

julie