There is good script by KKeith
http://www.daniweb.com/forums/post951182.html

I want to use it as my base script with some modification. Before I customize it, I want to Make it OOPized into class with functions in functions.php and login+register.phps
Please help me on doing that! I'm intermediate btn newbee and intermediate developer :)
Thanks!

Recommended Answers

All 7 Replies

Oh!
Here is the test page I'm using to try do that after I OOPize them

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- Consume Server: sfs-consume-2 -->
<?php
$test = '<big><b>* New PHP innovation award prize: PHP on Microsoft Visual Studio<br />
</b></big>
<br />
Before I proceed with the main subject of this post, I would like to mention something that I did not have the opportunity to mention in prior posts.<br />
<br />
The PHP Programming Innovation Award that happens every month on the PHPClasses site has a new prize that the winners may pick. It is the VS.PHP add-on. This is an add-on that allows you to use Microsoft Visual Studio as IDE for PHP. It was not developed by Microsoft, but rather by JCXSoftware.<br />
';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	<title>Login Script</title>
	<link rel = "stylesheet" type = "text/css" href = "/site/site.css">
  </head>
  
  <body>
	  <table cellpadding = "5px", cellspacing = "0", border = "1px", align = "center", id ="table">
		<tr>
			<td colspan = "2"> <h2 style = 'text-align:center;'>MY CONTENT MANAGEMENT SYSTEM</h2> </td>
		</tr>
		
		<tr valign = "top">
			<td width = "200px"> 
				<center><b>Navigation Bar</b></center><br /> 
				<?php	
					session_start(); //start session so we can login
					//include both files
					require('../site/admin/admin.login.php');
					require('../site/admin/admin.register.php');
					//from above file
					//check if login is clicked, otherwise press register
					if (isset($_GET['do'])){
						switch($_GET['do']){
							case 'login':
								echo $html_login;
								break;
							case 'register':
								echo $html_register;
								break;
						
						}// end switch
					}//end if
					else{
						 echo "<p>Member? <a href ={$_SERVER['PHP_SELF']}?do=login>Login</a>
						 <br />Guest? <a href ={$_SERVER['PHP_SELF']}?do=register>Register</a></p>";
					}//end else
					 echo "<div style=color:#ff0000'>{$message}</div>";
				?>
			</td>
			
			<td> <?php echo $test; ?> </td>
		</tr>
		
		<tr>
			<td colspan = "2" style = "text-align:center; background-color:black; color:white;"> Copyright &copy; 2009, New Bee Technologies</td>
		</tr>
	  </table>
  </body>
  
</html>

1st off - to 'OOP'ize code, you need to seperate views from the actual code.
2nd - Use a database class, an application class, and a main class.
3rd - Try to find a good templating system. I like phptal, and smarty works well too. You also can just include php files that are html with php variables in it, but no logic, like wordpress.

1st off - to 'OOP'ize code, you need to

seperate views from the actual code. -->Please explain here what you mean

2nd - Use a database class [Done]
, an application class, and a main class.--> Explain a little, please!

3rd - Try to find a good templating system. I like phptal, and smarty works well too. --> I will check them thanks :)

You also can just include php files that are html with php variables in it, but no logic, like wordpress.--> Please explain

Thanks for your reply, but I need to understand what you are saying. Please explain to me with grain of salt!

seperate views from the actual code. -->Please explain here what you mean

Basically, when you code, you cannot do this:

<?php
// php code here
?>
<html tag="something">
<?php
// More php code
?>

You would need to have your logic (PHP) in a file when then returns values which you display in a separate file which also handles the layout/visual stull (HTML)

A template system like Smarty will help you do this as it makes it much harder to just add in random PHP.

2nd - Use a database class [Done]
, an application class, and a main class.--> Explain a little, please!

class user would handle ass user functions.
class database would handle database transactions.
You get the idea?

I get it. I see people recommending smarty, but really I see it as mystery. Is there a newbie tutorial? Also back to my question, I see alot of things duplicating themselves in both register.php and login.php. would combining them into function be good idea?

An overview of smarty http://blog.themeforest.net/tutorials/smarty/.
I like phptal more, and I think it's easier to learn. The handbook / guide on the linked site above provides everything you'll need to use it.
For instance, I'm running http://quiz.codejoust.com/ with this as my index.php file :

<?php

require_once 'phptal.php';
require_once 'Data.class.php';
require_once 'Quizzer.class.php';
 
header('Content-Type: text/html; charset=utf-8');
  
$Quizzer = new Quizzer;	
 
 $tpl = new PHPTAL('Templates/layout.xhtml');
      
      /** Start Classes **/
            
      $tpl->Quizzer = $Quizzer;
      $tpl->action = ucwords($Quizzer->action);
      $tpl->loc = $_SERVER['PHP_SELF'];
      
      echo $tpl->execute();

All the logic is in the quizzer class, and I use phptal metal for each page to render an action. The data class is referenced by the quizzer class... and I have a few subclasses in there too (for passing around objects).
I find myself passing around arrays in php, not objects like ruby more because it's a easier way to move information.

In the database class, I have a _construct and a _destruct function, destruct disconnects, and construct checks if there is a static database variable for the class set, if not, it connects to the db.

The methods are such as $this->data->updateQuiz((array) $info) , which are called from the Quizzer class.

I'd use a main layout file, or a header and footer file, including the content in the middle.

What sort of application are you modifying?

I'm Making simple CMS for a site!
I will check that! I need secure Login/Register class. That is why I want to OOPize the one KKeith wrote and learn from there rather than reinverting the wheel.

I'm little busy with work now but when I get little time I will try to mess up with the files to come up with class. Hope Keith will help also:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.