Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  


Search Forums

(Advanced Search)

Forum Statistics
» Members: 344
» Latest member: inetsolution30
» Forum threads: 4,202
» Forum posts: 4,792

Full Statistics

Online Users
There is currently 1 user online
» 0 Member(s) | 1 Guest(s)

Latest Threads
Paul Jones' Blog: Rasmus ...
Last Post by: Guest
Today 02:42 AM
» Replies: 0
» Views: 0
Andi Gutmans' Blog: Zend ...
Last Post by: Guest
Today 02:42 AM
» Replies: 0
» Views: 0
Kae Verens' Blog: Moving ...
Last Post by: Guest
Today 01:06 AM
» Replies: 0
» Views: 0
Community News: phpGG Use...
Last Post by: Guest
Today 01:06 AM
» Replies: 0
» Views: 0
Chris Hartjes' Blog: Don'...
Last Post by: Guest
Today 01:06 AM
» Replies: 0
» Views: 0
Site News: Popular Posts ...
Last Post by: Guest
Yesterday 10:45 PM
» Replies: 0
» Views: 0
Total PHP: Browser based ...
Last Post by: Guest
Yesterday 07:37 AM
» Replies: 0
» Views: 0
Zoe Slattery's Blog: PHP ...
Last Post by: Guest
Yesterday 05:35 AM
» Replies: 0
» Views: 0
Zend Developer Zone: Usin...
Last Post by: Guest
Yesterday 05:35 AM
» Replies: 0
» Views: 0
Symfony Blog: New in symf...
Last Post by: Guest
Yesterday 03:55 AM
» Replies: 0
» Views: 0

 
  For is faster than While
Posted by: John - 02-14-2007 02:23 AM - No Replies

Cant remember where i read this but For is estimated to be upto 15% faster than the WHILE function.

MYSQL use of the WHILE tag

PHP Code:
while($arr mysqli_fetch_array($res)){

        echo 
$arr["description"];
            


Simply we can change this to the FOR function as below this is how it works

PHP Code:
for($i=0;$i<mysqli_num_rows($res);$i++) {

        
$arr=mysqli_fetch_assoc($res);
        echo 
$arr["description"];




Maybe this can help you with some overpowering websites Wink

-----------------------------------------------------------------

I executed the 2 files seperatly, 3 times.

FOR.php
1. 0.00317597389221
2. 0.00225114822388
3. 0.00206303596497

Average 0.00249671936035


WHILE.php
1. 0.00748109817505
2. 0.00274920463562
3. 0.00265097618103

Average 0.0042937596639

as you can see, WHILE has nearly doube the speed to execute which is not good! Stick with ya FORS

How i done the tests ive attached below.

- John



Attached File(s)
.rar File  FORvsWHILE.rar (Size: 1022 bytes / Downloads: 0)
 

  For Beginners
Posted by: melissajean85 - 12-22-2006 03:32 PM - No Replies

I'm just learning PHP so I thought I'd share a link I've found for a great PHP tutorial, http://www.freewebmasterhelp.com/tutorials/php/.

For those of you just learning, like me, PHP stands for Hypertext Preprocessor. I have yet to find out all of what PHP can do, but I'm looking forward to finding out.

If anyone has any resources that could help me, please share - I need all the help I can get. Tongue

 

  Geo-targeting Adsense and YPN
Posted by: Justin - 11-10-2006 11:14 AM - Replies (2)
0

As you know the Yahoo Publisher Network is in beta and only accepts U.S. traffic. If you send them non U.S. traffic you run the risk of getting your account banned. To do this you need to geo-target your ads so that users in the U.S. will see the YPN ads and visitors from anywhere else will see something different. A few people have asked me how to do this so I decided to write up a little tutorial.

First you will want to get a GEOIP database from the MaxMind website. I like to use the GeoLite Country database because it is free and still has a 97% accuracy rate. You can download the MaxMind database from http://www.maxmind.com/app/geoip_country and the latest version can always be found at http://www.maxmind.com/download/geoip/da...oIP.dat.gz . Try it with different proxies to test how accurate it is. Thats about all there is to it. You will have to update your GeoIP database every once in awhile to keep it up to date but other than that it need no maintenance. Of course you can always make it maintenance free by adding a cron script to update the DB for you but we will save that for another post Tongue Hope this helps Smile

 

  Creating an Ad Rotator
Posted by: Justin - 10-20-2006 11:54 AM - Replies (11)
0

PHP Code:
<?php
$result_random
=rand(1100);

if(
$result_random<=25){
echo 
"Display ad1";
}


elseif(
$result_random<=50){
echo 
"Display ad2";
}

elseif(
$result_random<=75){
echo 
"Display ad3";
}
?>


Very basic. It's pretty self explanatory.

 

  Contact From Tutorial
Posted by: Justin - 10-06-2006 12:54 PM - Replies (1)
0

In this tutorial you will learn how to make a simple contact form. It re-directs to an error page if errors are found and checks the email address for any "bad characters."

PHP Code:
<?php
if($submit=="Submit")
{
  if(empty(
$mail))
    
header("Location: index.php");
  elseif(!
CheckMail($mail) || empty($message)  || empty($subject))
  {
    
header("Location: error.php");
    Die(
"Please go back and fill in a valid e-mail adress!");
  }
}
?>

This little code here gets the whole thing started. The if statement comes to life when the "Submit" button is clicked. If a form is left empty it will redirect to error.php, if it all goes well it will redirect to index.php. You can change these if you want.

PHP Code:
<html>
  <
head>
    <
title>Request</title>
    <?
php
    extract
($_POST);
   
    function 
CheckMail($toCheck)
    {
if (
eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$"$toCheck))
        return 
true;
      return 
false;
    }
    
?>
  </head> 

The code here gets the information from the form and check the e-mail address for any characters that aren't allowed.

PHP Code:
<body>
    <
center>
    <?
php
    
if($submit!="Submit")
    {
    
?>
      <font size="5" style="color: Blue">Contact Form</font>
      <form method="post" action="">
        Name:<br />
        <input type="text" name="name" value="" /><br />
        Email:<br />
        <input type="text" name="mail" value="" /><br />
        Subject:<br />
        <input type="text" name="subject" value="" /><br />
<br/>
        Comments:<br />
<textarea name="message" rows="10" cols="50" value="Request details if applicable.">
</textarea>
<br />
        <input type="submit" name="submit" value="Submit" />
      </form> 

This is the form where information is entered. It's HTML so no need to explian.

PHP Code:
<?php
    
}
    else
    {
      
mail("YOUR E-MAIL ADDRESS HERE""{$subject} Request",
           
"Name: {$name}\nSubject: {$subject}\nMessage: {$message}",
           
"From: {$email}\r\nReply-To: {$email}");
    }
    
?>
    </center>
  </body>
</html> 

This closes it up and tells it where to send the information. Change "YOUR E-MAIL ADDRESS HERE" to the email address you want the information to be sent to.

 

  Introduction To Classes and Object Oriented Programming
Posted by: Justin - 10-02-2006 02:33 AM - Replies (1)
0

Learn a quick introduction to OOP (Object Oriented Programming). We will be creating a small class for fun to demonstrate how it all works.

In this tutorial we will be creating a class that will allow us to add up cars and then display the total weight of all the cars and also change the default weight per car.

So let's start the actual code part, for our script we will have 2 files. The first file we will be creating will contain our class, then the second file will include our class file and use our class to display the information we want.

Start of class.php

PHP Code:
<?php
class CarCounter
{
var 
$cars 0;
var 
$weightPerCar 500.0;

function 
add($n 1)
{
$this->cars $this->cars $n;
}

function 
totalWeight()
{
return 
$this->cars $this->weightPerCar;
}
}
?>


I just gave you the total code for our car class, I will now break it down and explain it. First we must define our new class by simply putting class then the name of the class that you want to create.

Then we define a variable. We create a variable called $cars. We will be using this variable to define how many cars we actually have, so we set this to 0 because we dont have any actual cars at the moment. Next we define another variable called $weightPerCar. This is the default weight per car. I have set this to 500.0, just a fictional number. Later on we will be changing the default weight though. Now we define a function within our class, this function will be used to just add more cars to our total. So we rightfully call this function cars. Then all we are doing is giving our function cars an argument, this is where we let the user put in as many cars as he wants to be added, we use the variable $n which will be used later on in the same function, we set $n to a default of 1. Then all we do is add $n to the current total.

Now we define our totalWeight function. This is where we calculate the total weight of all our cars by using the default totalWeight that we defined earlier. This works the same way as our add function except we are multiplying cars by totalWeight to get the weight of ALL our cars.

Then we close off our function and class and we are done with class.php, now we move onto cars.php where we actually use our class.

Start of cars.php

PHP Code:
<?php
require "class.php";

$cars = new CarCounter;
$cars->cars 5;

print 
"There are " $cars->cars " cars<br />";

$cars->add(10);

print 
"There are " $cars->cars " cars<br />";

print 
"Total weight = " $cars->totalWeight() . " kg<br />";

$cars->weightPerCar 700.0;

print 
"With the new weight per car, your total weight is now " $cars->totalWeight() . " kg";
?>


This is where we actually use our class, now to use our class we must first include it in our file. That is where we use the require. Now that our class file is included we can now use the class we defined in that file. Now to use the class and the member variables defined in the class we must create a new instance of the class. We can define our instance to a variable to use in our script.

This is where we have -

PHP Code:
$cars = new CarCounter


Once we have defined a new instance of our class we can now use the member variables defined in our class. So then we add 5 cars to our total.

Then we print what we have so far. Using our variable $cars, we can then access which member variable we need. cars was our member variable in our class that was set to 0. So now we set it to 5 to give it a value.

Now let's say we want to add more cars to our total we use our add function we created. So we use it the same way we would use a regular function except we must first say that it is in our class (Which is defined to our variable of $cars). So we add 10 more cars to our total so we now have 15 cars, and to prove this we print it out the exact same way we printed it out the first time.

Now with our 15 cars we want to find out the total weight of all 15 of these cars using the default weight we defined as one of our member variables. So we just do another print statement except we use the totalWeight function.

Now let's say we wanted to change the default weight of our cars, we can just give it a new value.

PHP Code:
$cars->weightPerCar 700.0


Then to prove that the weight actually did change we print out our totalWeight again except this time the function is using a new totalWeight default value so our total will be higher.

 

  Require_once and include_once
Posted by: Justin - 10-01-2006 07:17 AM - Replies (5)
0

The include and require functions are handy for using files that contain other variables, functions, etc. What happens when you have a collision between function names though? Well quite simply you get an error.

Say you have a function called name in a file called functions.php.

PHP Code:
function name()
{
//do something or return a variable


Now say you have file 1.php 2.php and 3.php and they all use this function and share some variables.

PHP Code:
require ("functions.php");
name();
//some variables 


PHP Code:
require ("functions.php");
name();
//some variables 


PHP Code:
require ("functions.php");
name();
//some variables 



Finally we have file named index.php which uses the values.

PHP Code:
include ("1.php");
include (
"2.php");
include (
"3.php"); 


Well index.php will cause an error that the function name has be redeclared. How do we fix it? Very easily. require_once is a function similar to the require that was used yet it only requires the file to be required one time. Therefore there is only one function called name. include_once works similarly except that is including the file and the file isn’t required.

PHP Code:
require_once ("functions.php");
name();
//some variables 


PHP Code:
require_once ("functions.php");
name();
//some variables 


PHP Code:
require_once ("functions.php");
name();
//some variables 



Now when including the files in index.php we don’t get the error.

 

  Simple Password Protection
Posted by: Justin - 09-26-2006 02:19 PM - Replies (5)
0

PHP - Creating a simple password protection.

1. Start out with you basic HTML page. Insert the code below and save this as protect.html.

Code:
<html>
      <head>
        <title>Password Protected!</title>
      </head>
         <center>


Note: Remove the centering if you wish

2. Now we start to build our forms in HTML. We'll start off with...

Code:
<form action="process.php" method="post">




The word "form" defines a form. Adding the word action defines where to send the data when the submit button is pushed.
the method="post" the ocntents of the form to be sent.

3. Below the code we just put in, you should now add the follwing code directly below it.

Code:
<input name="password" type="text" />
      <br/>



The word "input" defines an input field. The little code "field text" let's us now it will be a text field.
So far you shoul have a cod ethat looks like this...

Code:
<html>
      <head>
        <title>Password Protected!</title>
      </head>
      <body>
      <center>
      <form action="process.php" method="post">
      <input name="password" type="text" />
         </br>



4. We will insert one more line of code below what we have now.

Code:
<input type="submit" value="Submit" />



Once again the word "input" defines an input field. Now, we have some new stuff in there. Type determines what it will do. In this case the type is Submit. It will make a button and when the button is clicked it will submit all of our data we have in the document already.
Next we have "value" value is just the text that is displayed on the submit button change it if you would like to.

5. Now we must close all of our tags like so.

Code:
</form>
      </center>
      </body>
      </html>



This should be the code you have...

Code:
<html>
      <head>
        <title>Password Protected!</title>
      </head>
      <body>
      <center>

      <form action="process.php" method="post">
      <input name="password" type="text" />
      <br/>
      <input type="submit" value="Submit" />

      </form>

      </center>
      </body>
      </html>



<b>Remember save the file as protect.html!</b>

6. Now we are going to start the PHP file. Open a new document and save it as process.php.

7. Start off with you basic php tags.

PHP Code:
<?php

      ?>


8. All we are using is an if/else code so I will post the whole PHP code and explain.

PHP Code:
<?php
      
if ( $password == "yourpasshere" ) {
      
// header redirect to page
      
header"Location: blah.php" );
      
//or you can use an echo then a JS redirect
         /* echo "Correct!"; */
      
}else{
      
header"Location: blah.php" )
   
// echos the pass is wrong. you can use an echo with JS redirect or another header.
      
echo('Password is incorrect! ');
      }
      
?>



If starts the if function. $password is the varible and the two = signs means that the the pasword must match the word in the quotes. So if you would like to change
the password just change the word inside the quotes. Do not remeove the quotes! Below the if we have an echo. This echo is shown if the user enters the correct password. You may
change anything between the quotes.

Now we see the else funtion. This simply means if anything but the password is entered it will do whatever the else function tells it to.
In this case we tell it to die. Die just simply means stop. Since die is a funtion we must have these after it (). Between the parentheses we cna put text
to be displayed if the password is incorrect. You can change anything in there between the ' marks.

We are done! Close your php tags upload and enjoy!

Note: This is my first tut, so it probobly isn't the most secure pasword protect in the world. I will update with a more securre version soon!

 

  Hit Counter
Posted by: Justin - 09-26-2006 02:06 PM - Replies (6)
0

PHP - Hit Counter

In this tutorial you will learn how to make a stat counter that diplays total unqiue hits, unique hits today, total hits, and total hits today.

1. First, we need to create a database to store the information. You will need a database table called stats. This can simply be made by pasting the following code into the query box under the SQL tab in PHPmyAdmin.

Code:
CREATE TABLE `stats` (

`date` varchar(255) NOT NULL default '',

`ip` varchar(255) NOT NULL default ''

) TYPE=MyISAM;


2. Now we need to have a file to connect to the database. Copy this code and fill in your information. Save it as db_info.php.

Code:
$conn = mysql_connect("localhost","username","password"); mysql_select_db(db name) or die(mysql_error());


Fill in the correct information and place between PHP tags.

3. Now we start making the code for the site.

Code:
<?php
require ("db_info.php");
$date = date("M d, Y");
$hitadd= MYSQL_QUERY("INSERT INTO stats(date, ip)".
"VALUES ('$date', '$remad')");
?>


This code allows information to be sent to the databse. That information being the users IP address and the total # of hits. Place this on the page where you want stats to be taken from.

4 . Now we are going to display the hit counter.

Code:
<?php
require ("db_info.php");
$date = date("M d, Y");
$uniquetotals = mysql_query("SELECT DISTINCT ip FROM stats");
$uniquetotal = mysql_num_rows($uniquetotals);
$tdayuniques = mysql_query("SELECT DISTINCT ip FROM stats WHERE date = '$date'");
$tdayunique = mysql_num_rows($tdayniques);
$hitstotaltday = mysql_query("SELECT * from stats");
$hitstotal = mysql_num_rows($hitstotaltday);
$tdayhits = mysql_query("SELECT * from stats where date = '$date'");
$tdayhit = mysql_num_rows($tdayhits);

echo (" <b>Hits:</b> $hitstotal <br/> <b>Hits Today:</b> $tdayhits<br/> <b>Total Uniques:</b> $uniquetotal<br/> <b>Uniques Today:</b> $tdayunique");
?>


Your Done! Place the last code wherever you want the stats to be displayed.