PDA

View Full Version : First Line



Jam-ez
10-12-2008, 07:40 PM
Hi,

When you start a user system, DJ panel, SNS, or anything like that, what's the fist line of code you write, what's the first file you create?

Just thought it'd be nice to know where you all start, whether it be the installation page, the core, the index... the list just goes on, and on.

Jackboy
10-12-2008, 10:02 PM
Well my first line would be


<?php

First file is normally the database core. Depends what i'm making.

Calon
10-12-2008, 10:05 PM
Create folders (includes, images)
Create files (configuration.php - MySQL, class_library.php - Classes, index.php)

Then I kick off coding.

Jam-ez
11-12-2008, 04:34 PM
Create folders (includes, images)
Create files (configuration.php - MySQL, class_library.php - Classes, index.php)

Then I kick off coding.

Thanks for your help. <3

Luke
11-12-2008, 07:34 PM
When i do coding (rearely and very badly :P)
I usually start of with the configuration as people have said, then i usually get a basic login done,.

Calon
11-12-2008, 07:49 PM
The installation page would be a bad place to start, seeing as you haven't coded anything and you wouldn't know where to insert and what to insert.

Tomm
11-12-2008, 07:55 PM
A normally just copy my reusable database classes, etc. rather than remaking them for every project..

Calon
11-12-2008, 07:57 PM
A normally just copy my reusable database classes, etc. rather than remaking them for every project..
That's a good idea.

Jackboy
11-12-2008, 08:53 PM
A normally just copy my reusable database classes, etc. rather than remaking them for every project..

Makes sense... I like to rewrite though, because i feel that after every script i do my PHP has improved slightly

Excellent2
11-12-2008, 09:08 PM
If I'm making a usersystem or djpanel I usually kick off proceedings with my config file like so:


<?php

session_start();

$host = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "dbname";

$con = mysql_connect("$host","$dbuser","$dbpass")
or die(mysql_error());

mysql_select_db("$dbname",$con)
or die(mysql_error());

$logged_in = mysql_query("SELECT * FROM `table` WHERE `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");

$logged_in = mysql_fetch_array($logged_in);

$sitename = "Sitename";

?>
Then will come register and login, functions and so on.

Jam-ez
11-12-2008, 09:24 PM
When i do coding (rearely and very badly :P)
I usually start of with the configuration as people have said, then i usually get a basic login done,.


The installation page would be a bad place to start, seeing as you haven't coded anything and you wouldn't know where to insert and what to insert.


A normally just copy my reusable database classes, etc. rather than remaking them for every project..


Makes sense... I like to rewrite though, because i feel that after every script i do my PHP has improved slightly


If I'm making a usersystem or djpanel I usually kick off proceedings with my config file like so:


<?php

session_start();

$host = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "dbname";

$con = mysql_connect("$host","$dbuser","$dbpass")
or die(mysql_error());

mysql_select_db("$dbname",$con)
or die(mysql_error());

$logged_in = mysql_query("SELECT * FROM `table` WHERE `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");

$logged_in = mysql_fetch_array($logged_in);

$sitename = "Sitename";

?>
Then will come register and login, functions and so on.

Thanks for all the replies. I'm sure they'll come in handy for me and others. :)

Excellent2
11-12-2008, 09:27 PM
For me the config file is the first file that should be made as it's connecting everything up to the database.

Calon
12-12-2008, 07:32 PM
For me the config file is the first file that should be made as it's connecting everything up to the database.
We all have our different ways of coding, you don't use classes, more advanced coders do. Not saying I'm advanced as I'm still learning OOP.

Protege
12-12-2008, 09:34 PM
We all have our different ways of coding, you don't use classes, more advanced coders do. Not saying I'm advanced as I'm still learning OOP.

That made me lul quite hard

OOP in php = lul, good method to learn OOP but PHP isn't even OOP yet (might need to wait till php 6 or 7). tbh if you wana do OOP go learn java

The only reason I think OOP should be used is if you have multi instances, eg a chat engine.

THIS PROBS SPARK UP SOME ARGUEMENTS

Jackboy
12-12-2008, 09:39 PM
That made me lul quite hard

OOP in php = lul, good method to learn OOP but PHP isn't even OOP yet (might need to wait till php 6 or 7). tbh if you wana do OOP go learn java

The only reason I think OOP should be used is if you have multi instances, eg a chat engine.

THIS PROBS SPARK UP SOME ARGUEMENTS

WOW? You were right about arguments.

How the hell can you even suggest PHP isn't OOP yet?

I don't really know you Protege, i only know you from your funny comments :P, but PHP is OOP. I promise you.

I'm guessing your a procedural programmer?

Protege
12-12-2008, 09:42 PM
You where the last person i'd expect to spark up an argument, So tell me what you using OOP for in your scripts etc

Tomm
12-12-2008, 09:49 PM
That made me lul quite hard

OOP in php = lul, good method to learn OOP but PHP isn't even OOP yet (might need to wait till php 6 or 7). tbh if you wana do OOP go learn java

The only reason I think OOP should be used is if you have multi instances, eg a chat engine.

THIS PROBS SPARK UP SOME ARGUEMENTS

"The only reason I think OOP should be used is if you have multi instances, eg a chat engine."

You clearly have no idea what you are talking about...

I program in both Java and PHP and I can tell you that PHP is very much a OOP-capable language. The only thing it is really missing is namespaces which are due to be added very soon.

So before you go off on your rant you might like to check your facts.

Calon
12-12-2008, 09:49 PM
That made me lul quite hard

OOP in php = lul, good method to learn OOP but PHP isn't even OOP yet (might need to wait till php 6 or 7). tbh if you wana do OOP go learn java

The only reason I think OOP should be used is if you have multi instances, eg a chat engine.

THIS PROBS SPARK UP SOME ARGUEMENTS
http://muffinresearch.co.uk/archives/2005/01/25/oop-php-what-are-the-benefits/

Haven't read it all, but:

"Procedural code can be messy and hard to adapt later on. I currently work within a team of several developers where on occasion I have to modify other developer’s code. It’s usually the scripts which have utilised classes which can be quickly understood and changes be made without having to spend too much picking apart the code line by line to understand the flow."

Seems pretty valid, if you are working on a site with more than one person.

Protege
12-12-2008, 09:52 PM
http://muffinresearch.co.uk/archives/2005/01/25/oop-php-what-are-the-benefits/

Haven't read it all, but:

"Procedural code can be messy and hard to adapt later on. I currently work within a team of several developers where on occasion I have to modify other developer’s code. It’s usually the scripts which have utilised classes which can be quickly understood and changes be made without having to spend too much picking apart the code line by line to understand the flow."

Seems pretty valid, if you are working on a site with more than one person.

Fair play, but tell me what's wrong with having different "function" pages instead of classes, why do you use a class instead of an ordinary page of functions.


"The only reason I think OOP should be used is if you have multi instances, eg a chat engine."

You clearly have no idea what you are talking about...

I program in both Java and PHP and I can tell you that PHP is very much a OOP-capable language. The only thing it is really missing is namespaces which are due to be added very soon.

So before you go off on your rant you might like to check your facts.<- thats ranting

Just seeing your name i'd know you'd come up with some crap.

Same question as I asked Jackboy
So tell me what you using OOP for in your scripts etc

"So before you go off on your rant you might like to check your facts."
Why do I need to check my facts to give an opinion?

Calon
12-12-2008, 09:59 PM
Fair play, but tell me what's wrong with having different "function" pages instead of classes, why do you use a class instead of an ordinary page of functions.

http://www.phpguru.org/article/classes-vs-functions

To be honest, I just followed it as the other coders seemed to use it, then I was told it's a more advanced way, and now I've just found out that it's faster.

Excellent2
12-12-2008, 10:01 PM
But Calon you don't really code anything special so why would you bring OOP into it? You basically code usersystems?

Tomm
12-12-2008, 10:04 PM
I use OOP for my whole script.. You'll struggle to find any procedural code in my whole script.

Also how do you mean by: "Just seeing your name i'd know you'd come up with some crap."? Why don't you think about what you are saying before resulting to immature insults?

As to why? Check out this great link:
http://letmegooglethatforyou.com/?q=oop+advantages



Fair play, but tell me what's wrong with having different "function" pages instead of classes, why do you use a class instead of an ordinary page of functions.



Just seeing your name i'd know you'd come up with some crap.

Same question as I asked Jackboy
So tell me what you using OOP for in your scripts etc

"So before you go off on your rant you might like to check your facts."
Why do I need to check my facts to give an opinion?

Protege
12-12-2008, 10:04 PM
http://www.phpguru.org/article/classes-vs-functions

To be honest, I just followed it as the other coders seemed to use it, then I was told it's a more advanced way, and now I've just found out that it's faster.


Read a few comments, they're also interesting - at least you aren't in the argumentative move like Tomm ... scares me

&@Tomm Your script is some user system and basically using static instances, database.. continue

Btw, googling advantages @ OOP not OOP in PHP, im stating that OOP in PHP is stupid

I'll give you an advantage with a database class coded with the construct in this fashion (multi instances)


$mysql = new MySQL( 'host', 'user', 'pass' );
$mysql->connect();


$mysql2 = new MySQL( 'host2', 'user2', 'pass2' );
$mysql2->connect();

Thats the advantage i see with that class but do you connect to two databases or even create two instances of a class?

Jackboy
12-12-2008, 10:12 PM
Lmao sorry i'm slow to reply.

OOP is so much easier.

For instance using MVC. You cannot do that with just plain functions :D

Ahh gotta love OOP. Tomm is a brilliant programmer. He has advanced since his radio panel days :P

Tomm
12-12-2008, 10:18 PM
Hah! You think I just make UserSystems? You clearly have no idea...

If you really would like I know the kinds of thing I currently do, which i'd like to point out I no longer bother talking about on HxF, then I am more than happy to tell you.

Without sounding big-headed or whatever I am more experienced and advanced at PHP than you are and most likely will ever be with your current views.

Your example you gave with the MySQL connector is well crap. I find it hard to think of a real world situation where you would want to connect to two diffrent server. In my projects I normally use a singleton pattern database abstract layer class. This gives me a number of advantages. Mainly the ability to get the current instance anywhere in the script (No globals or passing the object from class to class) and allowing me to transparently change my database engine.


Read a few comments, they're also interesting - at least you aren't in the argumentative move like Tomm ... scares me

&@Tomm Your script is some user system and basically using static instances, database.. continue

Protege
12-12-2008, 10:25 PM
Hah! You think I just make UserSystems? You clearly have no idea...

If you really would like I know the kinds of thing I currently do, which i'd like to point out I no longer bother talking about on HxF, then I am more than happy to tell you.

Without sounding big-headed or whatever I am more experienced and advanced at PHP than you are and most likely will ever be with your current views.

Your example you gave with the MySQL connector is well crap. I find it hard to think of a real world situation where you would want to connect to two diffrent databases. In my projects I normally use a singleton pattern database abstract layer class. This gives me a number of advantages. Mainly the ability to get the current instance anywhere in the script (No globals or passing the object from class to class) and allowing me to transparently change my database engine.

Say you have this chat room you've produced and instead of using your own user database you want to use your forums, so you connect to that database but in your chat room you want to keep different information, say the users styles in chat (fonts, size, colour) so you use your own database for that (and for the other things in your chat room) - you'd need to connect to two databases.

So if you wanted to advance and do that, how could you do that with a singleton database class?

Another one is, You want your customers forum login and billing login to always stay the same etc.

Tomm
12-12-2008, 10:30 PM
Your example showed connecting to two different servers completely. My mistake in my post with the use of `database`.


Say you have this chat room you've produced and instead of using your own user database you want to use your forums, so you connect to that database but in your chat room you want to keep different information, say the users styles in chat (fonts, size, colour) so you use your own database for that (and for the other things in your chat room) - you'd need to connect to two databases.

So if you wanted to advance and do that, how could you do that with a singleton database class?

Another one is, You want your customers forum login and billing login to always stay the same etc.

Calon
12-12-2008, 10:44 PM
But Calon you don't really code anything special so why would you bring OOP into it? You basically code usersystems?
I don't see how social networking scripts are just user systems. (Next version I'm coding of Nivade)
I don't see how an order system is a user system (Sold, freelance work)

Excellent2
12-12-2008, 11:07 PM
I don't see how social networking scripts are just user systems. (Next version I'm coding of Nivade)
I don't see how an order system is a user system (Sold, freelance work)You call Nivade a social networking script? Lol! And an order system is nothing but someone submitting and order, it going through a member of staff who checks it, charges the person and sets up the account. BAM.

Calon
12-12-2008, 11:37 PM
You call Nivade a social networking script? Lol! And an order system is nothing but someone submitting and order, it going through a member of staff who checks it, charges the person and sets up the account. BAM.
Order script actually uses the paypal API - thanks.
Social networking script - Yes, because I created it, and it's a script, it's a social networking script shall I define this for you or just break it down?

Excellent2
13-12-2008, 02:45 AM
Order script actually uses the paypal API - thanks.
Social networking script - Yes, because I created it, and it's a script, it's a social networking script shall I define this for you or just break it down?Congratulations Calon, you can work with the paypal API! :eusa_clap And it's more of a user system seeing as you don't have half the features a standard SN has.

Source
13-12-2008, 02:48 AM
Just stop picking, spend more time learning and improving your php for goodness sake. If you spent half as much time coding/learning than arguing you might actually be a better coder that can get things done quickly to a high standard.

That applies to both of you (and me, admittedly). I think HxF needs to employ a nanny or someone to look after you lot.

Calon
13-12-2008, 06:06 PM
Just stop picking, spend more time learning and improving your php for goodness sake. If you spent half as much time coding/learning than arguing you might actually be a better coder that can get things done quickly to a high standard.

That applies to both of you (and me, admittedly). I think HxF needs to employ a nanny or someone to look after you lot.
Admittedly, includes you.

Want to hide these adverts? Register an account for free!