TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-18-2007, 08:53 PM   #21 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
so if I were to do this:
PHP Code:
$sql printf("SELECT `u_id`, `username`, `password`, `registerdate`, `registerip` FROM `".$this->table['members']."` WHERE `u_id` = %d"$u_id);
$this->data $this->db->fetch($sql); 
it would mean that $data['username'] would be the value of the username row?
Why don't you try it? :p
Haris is offline  
Reply With Quote
Old 09-18-2007, 09:00 PM   #22 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Because my webserver still don't work with classes as I've said 100 times before.. :S :(
Tanax is offline  
Reply With Quote
Old 09-18-2007, 09:55 PM   #23 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

How can it not work with classes?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-18-2007, 10:50 PM   #24 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Don't ask me, ask the distributor of xampplite :P
Tanax is offline  
Reply With Quote
Old 09-18-2007, 11:03 PM   #25 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default

That's why http://www.wampserver.com/en/ is more preferred.
Haris is offline  
Reply With Quote
Old 09-18-2007, 11:05 PM   #26 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I do like WAMP, me.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-19-2007, 05:04 AM   #27 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Well, I'll try with that one too then :P And we'll see if it works :P
Tanax is offline  
Reply With Quote
Old 09-19-2007, 08:03 AM   #28 (permalink)
The Contributor
 
Shaun's Avatar
 
Join Date: Sep 2007
Posts: 41
Thanks: 0
Shaun is on a distinguished road
Default

i WAMP as well :)

quick and easy, and slack
Send a message via MSN to Shaun Send a message via Skype™ to Shaun
Shaun is offline  
Reply With Quote
Old 09-19-2007, 11:25 AM   #29 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

lazy WAMP users, I do it the old fashioned way - takes me bloody ages :(
Karl is offline  
Reply With Quote
Old 09-19-2007, 01:16 PM   #30 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I do it the old fashioned way too (kinky!). By that I mean installing Apache, PHP and MySQL individually... took me around 5 minutes. :p
Salathe is offline  
Reply With Quote
Old 09-19-2007, 01:34 PM   #31 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

lol it takes my excuse of a computer more than 5 mins just to extract and install the actual product, never mind the time to configure them :(
Karl is offline  
Reply With Quote
Old 09-19-2007, 02:59 PM   #32 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

PHP Code:
class person {
        
        private 
$namn;
        private 
$age;
        
        public function 
setName($name) {
            
            
$this->name $name;
            
        }
        
        public function 
setAge($age) {
            
            
$this->age $age;
            
        }
        
        public function 
intro() {
            
            echo 
'Hello, my name is ' .$this->name' and I\'m ' .$this->age' years old!';
            
        }
        
        
    }
    
    
$marcus = new person();
    
$marcus->setName('Marcus');
    
$marcus->setAge(18);
    
    
$marcus->intro(); 
Working!!! Thanks for the tip about WAMP :D Now I'll try to compile my main classes..

And btw, I haven't coded the files USING the classes. I've only coded the files WITH the classes. So it'll take a while though until I can try this :P
Tanax is offline  
Reply With Quote
Old 05-04-2009, 07:07 PM   #33 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Hello, I'm new to this forum, and I'm not exactly sure if this is the correct place to post this, but I hope it is.

Anyways, I've done 2 classes, a database class that handles the database querys and general stuff with the database, and a member class that manages the members in the database.

And yea, I know that my comment lines are big.

_database.php
PHP Code:
<?php

/**
||||||||||||||||||||||||||||||||||||||||||
|||| @author Tanax
|||| @copyright 2007
||||||||||||||||||||||||||||||||||||||||||
**/

    
class database {
          
          private 
$db = array();
          
          
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Our constructor that auto-loads
        ||||||||||||||||||||||||||||||||||||||||||
        **/
          
public function __construct($host$user$pass) {
                
            
$this->db['host'] = $host;
            
$this->db['user'] = $user;
            
$this->db['pass'] = $pass;
                
            
$this->connectdb();
                        
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Connect to db
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
private function connect() {
            
            @
mysql_connect($this->db['host'], $this->db['user'], $this->db['pass']) or die('Could not connect to the database!');
                    
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Select db
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function select($name) {
            
            
$this->db['db'] = $name;
            @
mysql_select_db($this->db['db']) or die('This system has not been installed, or something is wrong in the database table!');
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Disconnect db
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function disconnect() {
            
            
mysql_close();
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Makes a query
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function query($string) {
            
            
$result mysql_query($string);
            
            return 
$result;
            
        }

       
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Fetches a result
        ||||||||||||||||||||||||||||||||||||||||||
        **/

        
public function fetch($string) {
            
            
$result mysql_fetch_array($string);
            
            return 
$result;
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Makes a value safe from SQL injection
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function makesafe($string) {
            
            
$result mysql_real_escape_string($string);
            
            return 
$result;
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Installs a system, adding tables
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function install($system$tablename) {
            
            if(
$system == "membersystem") {
                
                
$create "CREATE TABLE `".$tablename."` (
                
                    `u_id` int(11) NOT NULL auto_increment,
                      `username` varchar(25) NOT NULL default '',
                      `registerdate` int(25) NOT NULL default '',
                      `registerip` varchar(32) NOT NULL default '',
                    PRIMARY KEY  (`u_id`)
                
                ) TYPE=MyISAM AUTO_INCREMENT=60"
;
                
            }
            
            elseif(
$system == "memberpm") {
                
                
$create "CREATE TABLE `".$tablename."` (
                
                    `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
                    `title` VARCHAR( 255 ) NULL,
                    `message` TEXT NOT NULL,
                    `from` INT( 11 ) NOT NULL ,
                    `to` INT( 11 ) NOT NULL ,
                    `from_viewed` BOOL NOT NULL DEFAULT '0',
                    `to_viewed` BOOL NOT NULL DEFAULT '0',
                    `from_deleted` BOOL NOT NULL DEFAULT '0',
                    `to_deleted` BOOL NOT NULL DEFAULT '0',
                    `from_vdate` DATETIME NULL,
                    `to_vdate` DATETIME NULL,
                    `from_ddate` DATETIME NULL,
                    `to_ddate` DATETIME NULL,
                    `created` DATETIME NOT NULL

                ) ENGINE = MYISAM"
;
                
            }
            
            
$insert $this->query($create);
            if(
$insert) {
                    
                
$msg "Table :" .$tablename" was successfully created!";
                return 
$msg;
                    
            } else {
                    
                
$msg "Table: " .$tablename" could not be created!";
                return 
$msg;
                    
            }
            
        }
        
    }

?>
So that was the database class, this is the membersclass.

_members.php
PHP Code:
<?php

/**
||||||||||||||||||||||||||||||||||||||||||
|||| @author Tanax
|||| @copyright 2007
||||||||||||||||||||||||||||||||||||||||||
**/

    
class member {
        
        private 
$db;
        private 
$data = array('u_id' => '''username' => '''password' => '''registerdate' => '''registerip' => '');
        private 
$table = array();
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Our constructor that auto-loads
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function __construct(database $db$tablename) {
            
            
$this->db $db;
            
$this->table['members'] = $tablename;
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Creates, or updates a member
        ||||||||||||||||||||||||||||||||||||||||||
        **/

        
public function save();

        
$sql sprintf('INSERT INTO
                    %1$s
                    (username, password, registerdate, registerip)
                VALUES
                    ("%2$s", "%3$s", "%4$s", "%5$s")
                ON DUPLICATE KEY
                UPDATE
                    username = "%2$s",
                    password = "%3$s",
                    registerdate = "%4$s",
                    registerip = "%5$s"'
,
                
$this->table['members'],
                
$this->data['username'],
                
$this->data['password'],
                
$this->data['registerdate'],
                
$this->data['registerip']);

        
$this->db->query($sql);
        }
                
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Checks if user is loaded
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function isLoaded() {
            
            return isset(
$this->data['id']);
    
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Loads a user by ID
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function load($u_id) {
            
            
$sql printf("SELECT `u_id`, `username`, `password`, `registerdate`, `registerip` FROM `".$this->table['members']."` WHERE `u_id` = %d"$u_id);
            
$this->data $this->db->fetch($sql);    
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Searches for a user by name
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function find($name) {
        
            
$name $this->db->makesafe($name);
            
$sql printf("SELECT `u_id` FROM `".$this->table['members']."` WHERE `username` = %s"$name);
            
$id $this->db->fetch($sql);

            
// If anything was found
            
if(isset($id['id'])) {
                
                
$this->load($id['id']);
        
            }
        
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Gets ID of loaded user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function getId() {
            
            if(!isset(
$this->data['u_id'])) {
                
                
trigger_error('Tries to get property of not loaded user.'E_USER_NOTICE);
                return 
false;
        
            }

            return 
$this->data['u_id'];
    
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Gets name of loaded user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function getName() {
            
            if(!isset(
$this->data['username'])) {
                
                
trigger_error('Tries to get property of not loaded user.'E_USER_NOTICE);
                return 
false;
        
            }

            return 
$this->data['username'];
    
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Sets name of user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function setName($name) {
            
            
$name $this->data->makesafe($name);
            
$this->data['username'] = (string) $name;
    
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Gets password of loaded user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function getPass() {
            
            if(!isset(
$this->data['password'])) {
                
                
trigger_error('Tries to get property of not loaded user.'E_USER_NOTICE);
                return 
false;
                
            }
            
            return 
$this->data['password'];
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Sets password of user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function setPass($pass) {
            
            
$pass $this->data->makesafe($pass);
            
$this->data['password'] = $pass;
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Gets registerdate of loaded user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function getRegdate() {
            
            if(!isset(
$this->data['registerdate'])) {
                
                
trigger_error('Tries to get property of not loaded user.'E_USER_NOTICE);
                return 
false;
                
            }
            
            return 
$this->data['registerdate'];
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Sets registerdate of user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function setRegdate($date) {
            
            
$this->data['registerdate'] = $date;
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Gets registerip of loaded user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function getRegip() {
            
            if(!isset(
$this->data['registerip'])) {
                
                
trigger_error('Tries to get property of not loaded user.'E_USER_NOTICE);
                return 
false;
                
            }
            
            return 
$this->data['registerip'];
            
        }
        
        
/**
        ||||||||||||||||||||||||||||||||||||||||||
        |||| Sets registerip of user
        ||||||||||||||||||||||||||||||||||||||||||
        **/
        
public function setRegip($ip) {
            
            
$this->data['registerip'] = $ip;
            
        }
    
    }

?>

So I'm just wondering if you see any errors, or if you see anything that could be done better/safer.


Hey Tanax,

Is this code still good or have you updated it to something better?

I'm sure your OO skills have improved since 2007!!!

allworknoplay is offline  
Reply With Quote
Old 05-04-2009, 07:11 PM   #34 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
I do it the old fashioned way too (kinky!). By that I mean installing Apache, PHP and MySQL individually... took me around 5 minutes. :p
I love doing it this way too....I've never really used RPM or yum to install packages as I don't feel like I know what I am doing...

I mean, I'd use RPM or yum for say installing an NTP or FTP server, but for LAMP setups, I like to do them individually and set the configure options to my specific needs.....

When I build linux, I usually build it as barebones as possible, I don't have it install mysql, apache etc...
allworknoplay is offline  
Reply With Quote
Old 05-04-2009, 11:00 PM   #35 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
Hey Tanax,

Is this code still good or have you updated it to something better?

I'm sure your OO skills have improved since 2007!!!

Haha wow! You dig up old posts
Well, if you're looking at it as a learning purpose, then studying these classes are quite good practice.

And yes of course I've come up with better stuff! I created database classes(3 files) and one of them were over 1000 lines of code! A little more advanced than this I would say

I haven't created a new member system though, but could probably pretty easially create one

And I sure hope they have! LOL
__________________
Tanax is offline  
Reply With Quote
Old 05-04-2009, 11:33 PM   #36 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Haha wow! You dig up old posts
Well, if you're looking at it as a learning purpose, then studying these classes are quite good practice.

And yes of course I've come up with better stuff! I created database classes(3 files) and one of them were over 1000 lines of code! A little more advanced than this I would say

I haven't created a new member system though, but could probably pretty easially create one

And I sure hope they have! LOL
I know, the way I see it, I have to at least try to dig up old threads to see if I can learn anything that has been talked about the last 2 years here...

I'm actually playing with your code now...is this a typo?

I see that in your construct, you are calling this method:

$this->connectdb();

But that method doesn't exist anywhere in the class, the closest is:

connect();


So once I implement this, what would you say is next for me in terms of database connection and OO?


What is the next step!!!

EDIT:

Also this is OT, but do you know of any way to initialize multiple arrays at the same time? So instead of this:

$test = array();
$test2 = array();
$test3 = array();

You can somehow create those 3 arrays with a single command?
Does PHP have anything built in for that?
allworknoplay is offline  
Reply With Quote
Old 05-05-2009, 09:29 AM   #37 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by allworknoplay View Post
I know, the way I see it, I have to at least try to dig up old threads to see if I can learn anything that has been talked about the last 2 years here...

I'm actually playing with your code now...is this a typo?

I see that in your construct, you are calling this method:

$this->connectdb();

But that method doesn't exist anywhere in the class, the closest is:

connect();


So once I implement this, what would you say is next for me in terms of database connection and OO?


What is the next step!!!

EDIT:

Also this is OT, but do you know of any way to initialize multiple arrays at the same time? So instead of this:

$test = array();
$test2 = array();
$test3 = array();

You can somehow create those 3 arrays with a single command?
Does PHP have anything built in for that?
Well it's good that you want to learn

Yes, sorry - that's a typo, should be connect() obviously.
Next step would be .. create a registration page and login page and implement the classes! I promise that it's not as easy as one may think

About the arrays I have no idea. I don't think any language has that? You have to create variables for each array you want to create in any language, so.. You could possibly do it in one line like this:

$test = array(), $test2 = array(), $test3 = array();

but I'm not sure.
__________________
Tanax is offline  
Reply With Quote
Old 05-05-2009, 09:51 AM   #38 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Wow this is an old thread!
Quote:
I love doing it this way too....I've never really used RPM or yum to install packages as I don't feel like I know what I am doing...

I mean, I'd use RPM or yum for say installing an NTP or FTP server, but for LAMP setups, I like to do them individually and set the configure options to my specific needs.....

When I build linux, I usually build it as barebones as possible, I don't have it install mysql, apache etc...
Yea me too, I prefer the good ol' fashioned:

wget tar ./configure [if this is PHP there will be a MASSIVE list of flags here] (fix any missing packages, get angry when the ubuntu's apt-get repository only has the old version, lynx google wget tar ... and so on) make && make install
rinse and repeat

The ubuntu server's install LAMP option is OK i suppose, but i'd prefer to build them with specific flags so that i only have enabled what i need (performance is a tricky animal to tame), also I'm sure that its setup securely (I'm sure the automatic LAMP install is secure, but I'm paranoid you see)

Quote:
About the arrays I have no idea. I don't think any language has that? You have to create variables for each array you want to create in any language, so.. You could possibly do it in one line like this:

$test = array(), $test2 = array(), $test3 = array();

but I'm not sure.
PHP Code:
$array1 $array2 $array3 = array(); 
That *should* work.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:47 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design