Jump to content


gizmola

Member Since 06 May 2003
Offline Last Active Apr 14 2014 06:41 PM

#1475800 Banner ad Rotation

Posted by gizmola on 11 April 2014 - 02:39 PM

To make it database driven you simply need to create a banner table.

You'll want to have a structure like this:
 
id int (primary key)
url varchar(512)
image varchar(128)
active tinyint
As for rotation, so long as your banner ad table doesn't get larger than a thousand rows, there isn't much of a concern, however, I would highly recommend reading this blog post: http://jan.kneschke..../order-by-rand/

With that said, the simplest solution for you, that will certainly work fine for quite a while:
 
SELECT * FROM banner WHERE active = 1 ORDER BY RAND() LIMIT 1
If you expect rotation over time without reloads, then cyberRobot's point should be taken into account. Often people will utilize an iframe and place the banner in the iframe, which can then have a simple meta refresh tag in the header of the code.

Ajax polling offers a more sophisticated option to cyberRobot's point, or you could alternatively fetch a number of ads initially and use a javascript timer to rotate them.


#1473739 New Moderator: mac_gyver

Posted by gizmola on 24 March 2014 - 03:00 PM

Congrats mac, agree with Phillip - you have really helped to keep phpf running, and your efforts are appreciated.




#1471661 Newbie Questions (EASY)

Posted by gizmola on 06 March 2014 - 12:47 PM

What have you tried?

I suggested that you:

Put the mail chimp code into a file named mailchimp.inc.php

There should NOT be a <?php at the top. Simply put that code exactly as is, in the file.

This file should be in the same directory as your template.

In the template add: include('mailchimp.inc.php');


#1471109 Hiring programmers, are there copyright laws?

Posted by gizmola on 28 February 2014 - 07:56 PM

right.. but the problem is with proving and enforcing it.


Agree 100%.

I've had these types of conversations with people probably 50x over the years, I have NEVER seen a case that didn't involve a patent.

Every other business person I talk to, who has an idea, is convinced their idea is amazing and original and worth a billion dollars.


#1468366 What's the use of abstract classes/methods?

Posted by gizmola on 10 February 2014 - 01:02 AM

There are times when you want to create a number of subclasses that all inherit from the same base class, but insure that the base class can not be instantiated itself.  A simple example would be a zoo simulation where you decide that you want to have a factory class that can "make" new animals.  When your application needs to create a new lion, for example, you don't want to have to write the same code over and over, when you can instead have completely generic code that creates animals of any type.

 

Once an animal object is created, you will probably need to call some standard methods, and again if you based all your specific animal classes off an abstract animal class, your non-abstract methods can be called.  Imagine you need some code that Will store an animal name, birthdate, gender and location in a table. You may decide that for each animal class you'll have a seperate table  with the same name as the class.  So in this example, you will have a lion table in the database.

 

In your abstract animal class you might have:

//Animal class.
public function saveNew() {
    $table = get_class($this);
    $this->db->$table->insert(array('name' => $this->name, 'birthdate' => $this->birthdate, 'location' => $this->location, 'gender' => $this->gender));
}
 

Needless to say, you will not have an 'animal' table, so making the baseclass abstract provides some protection against issues with saveNew(). 

 

It also provides a standard set of methods the factory class can depend on, so it can feature code like:

// Animal Factory class
 
public function makeAnimal($type, $location) {
    $animal = new $type($location);
    $animal->setGender();
    $animal->setName();
    $animal->saveNew();
}

This code can be depended upon to work for any animal class that inherits from 'Animal'.  setName() is an example where you might want to have an abstract method, assuming that the rules for animal names would be different for each different type of animal.  The factory class will call setName(), but it is up to you to actually write function setName() when you create each individual class. 

 

SetGender()_ is another example, where you might lookup the relative ratio of male to female animals in a table where each row is named by class.  While you would have a row for lion, elephant and crocodile, you'll have no row for animal.

 

When trying to really dig into these ideas, you'll quickly find yourself gravitating towards "Object oriented design patterns".  The books on this subject will provide specific examples that should help you understand why the oop features in php were implemented in ways that the manual does not. 




#1468004 Contact Form Not Working, any idea why?

Posted by gizmola on 06 February 2014 - 08:27 PM

mail() depends on the configuration of your specific server, and the underlying mail transfer agent mechanics.  I don't see anything obviously wrong with your code, although there could be something subtle.  If the mail() function is succeeding, you need to debug at the MTA level.  For example, if you were on a linux server and the mail is being dumped off to sendmail or postfix there are ways to determine if the mta is successfully delivering the mail.

 

Mail server configuration also includes details about DNS MX, SPF and DKIM, not to mention the core SMTP standard.  If you're just developing on a local workstation its probable that you don't have a working mail configuration OR you do have one, and the mail is being delivered, but due to the lack of the aforementioned environment, your mail is being spam filtered or outright rejected.




#1465239 MySQL Load Balancing between 2 or more servers?

Posted by gizmola on 14 January 2014 - 02:03 PM

MySQL really doesn't support load balancing for writes.  It does support slaves/replication for reads.  So the idea of putting a load balancer in front of a set of mysql servers isn't used from what I've seen.

 

I think what you're really looking for is:  http://dev.mysql.com...tion-howto.html

 

You can google for mysql replication and get more information. 




#1465233 Need help for learning PhP

Posted by gizmola on 14 January 2014 - 01:43 PM

PHP programming is not complicated.  Web development is complicated, and PHP is highly focused on solving web development problems. 

 

As you stated, you need to learn a lot of things:   

 

  • How does the WWW work?
  • How does the internet work?
  • What is HTML?
  • What is CSS?
  • What is javascript?  Why, when where do you need javascript?
  • What is HTTP and what do I need to know about it?
  • What features do browsers offer, and why/when are the used?  (Cookies, HTML5)
  • How do I setup the various servers and modules needed in order to code specific things (unix/linux, command lines, etc.)

All of this before you even can really turn the corner on what PHP does, or get into data persistence (files, relational database and document stores, caches, etc).

 

Based on what you've said, I would highly recommend, that you learn html + css to the point that you can create and style a nice web page.  This includes building forms using all the various form input types.  The good news is that there are so many free resources available not to mention places like codeacademy, all for free, and you don't need anything but a browser and a text editor to study and practice.

 

After that you can either proceed to javascript, or start in on PHP.  Personally, I'd recommend adding javascript, at least to the degree that you can do some basics.  Learning jquery around this time would not be a bad thing either.

 

Once you can create web pages, with HTML, css and javascript, you're ready for PHP.  Trying to dive into PHP without those foundation elements, can certainly be extremely confusing, because you don't have any context for many of the features of PHP.

 

Also, all the browsers have tools now like firebug that let you look into the workings of existing web pages, or the ones you create, so that you can debug javascript, look at the DOM, check out the HTTP requests.  I would have killed for tools like these when I was starting out in this field. 




#1463080 best way to crypt a password

Posted by gizmola on 25 December 2013 - 04:48 PM

In my opinion, the best solution is not to encrypt the password but to hash it.  A hash can not be decrypted. 

 

As entire books have been written on this subject, and it's non-trivial I'll try and limit myself to a few comments.

 

md5 is one such hash, and is not a terrible choice if you take other precautions, however, there are better hashes available -- sha1 for example.

 

It's very important that you use a salt when you're hashing the password.

 

The best practice lately, is that you hash or encrypt passwords using a large number of repeated operations.  For example, rather than hash the password once, you might hash it 500x using the result and re-hashing it over and over again.  This slows down the operation, so that people attempting brute-force hacks, or who compromise your entire user table, will face a substantial barrier to utilizing a rainbow table and determining simple matches. 

 

In your code, I'd suggest you write a simple function that does the hashing routine.  As input it requires the username, the password, the salt, and a randomly generated number of hash operations to be repeated.  Of course you need to generate and store all these in your user table, so this will require some modifications and some routines that will generate random numbers in a range, and random strings to use as salts.

 

You then compare the stored password with this result and if == the user has authenticated.

 

Do not store the password in the session. 




#1460056 How can I select data from two tables (using an intermediate table)?

Posted by gizmola on 25 November 2013 - 04:50 PM

Yes there is a simple way, and it's named "join", or "joining" the tables together.
 
There are several syntaxes you can use to do the same thing.  In this case, all your joins are going to be "inner" joins, so what you want is to use "Left Inner" joins from your user_student table back to user and student, respectively.
 
SELECT u.name, s.name
FROM user_student us
LEFT JOIN user u ON u.id = us.user_id
LEFT JOIN student s ON s.id = us.student_id
This person created a nice site that really breaks down and makes clear the syntax and the different variations you can use. http://mysqljoin.com/


#1442742 How would you approach this? (PHP PBP Engine Advice)

Posted by gizmola on 30 July 2013 - 10:21 PM

We don't delete threads, especially ones where someone took the time to reply to you, as I did.


#1441023 Booking/reservation system in symfony2

Posted by gizmola on 17 July 2013 - 03:57 AM

What is your question?  

 

You have an ambitious set of requirements.  

 

In most cases someone has already tackled the problem and you should do some research to see if there are bundles or libraries that you can build upon.  

 

For example:

 

This one is javascript/jquery oriented and helps you integrate FullCalendar which in turn provides the option to plugin to google calendar:  https://github.com/a...calendar-bundle

 

This one uses doctrine (and hence will store the data in mysql if that's your preference): https://github.com/c...calendar-bundle

 

I'd suggest you do some research, play and explore these, and perhaps other symfony2 bundles, and try and get something in place you can build upon.




#1437145 How to send mail via command "HELO" "MAIL FROM"?

Posted by gizmola on 20 June 2013 - 07:23 PM

In your example, you have an email where the sender is "someone@yahoo.com".

Almost all systems do the following:

- Check the sender domain (yahoo.com)
- Get the mx records for that domain using DNS
- Is this server who is connecting to me, an mx for yahoo.com?

In your case, the answer is NO. The email will be either rejected, or accepted and immediately deleted from their queue.

Obviously you are not even getting to that point, however, it is likely that you will end up there.

Your immediate issue is this, the mx records for hotmail are:

5 mx2.hotmail.com
5 mx3.hotmail.com
5 mx1.hotmail.com
5 mx4.hotmail.com

Again, if you don't understand SMTP and how email works, why are you trying to write your own SMTP stack?


#1436902 How to send mail via command "HELO" "MAIL FROM"?

Posted by gizmola on 19 June 2013 - 02:43 PM

Thanks, but i want send email via command HELO.

Why hotmail.com disconnect my?

 

First off... what you are saying you want to do is implement the SMTP protocol.  That is non trivial, and the libraries suggested provide full implementations of those protocols.  With that said, mail transfer agent (MTA) configuration and email verification in the age of spam is a fact of life.  Email systems like hotmail do all sorts of things to verify where email is originating from, not limited to, checking for MX records, reverse dns verification, SPF verification and DKIM.  In your example, trying to spoof a yahoo.com email sender is likely to just be rejected outright as spam because you will fail all sorts of spam checks on their server.  They don't want people doing what you're trying to do, and you're wasting your time trying it.

 

Of course there could also be a simpler explanation of your outright disconnection, in that hotmail.com is now defunct/deprecated and hotmail is now outlook.com.  See:  http://geeks.broadwa...-Years-20130503

 

Even if it wasn't shutdown, there is really no reason to reinvent the wheel for smtp, with libraries that do it for you, not to mention, the mail() function.




#1436023 Standard Mysql/Database Practice?

Posted by gizmola on 14 June 2013 - 02:25 PM

You have picked up a lot from the looks of your table design. Having designed scores of databases for all sorts of companies, I can tell you that I find an ER Design tool an essential part of my tool kit, and I always start a project out either with a new ERD (Entity relationship design) or by reverse engineering an existing database. It's much easier for developers on a team to communicate about the implicit design when there's a simple diagram to refer to, and seasoned developers who have to deal with databases usually can read these and understand a lot about the implicit design decisions just by looking at how the tables relate to each other.

A lot of these tools tend towards the pricey - 2 I've used in the past typically cost $500-$1k+ (CA Erwin & Embarcadero ER Studio) although in recent years I've been using a product named Dezign for databases which used to be a great bargain, but over the years has crept up to the $300 range. If you're concentrating on MySQL at the moment, then you have the option of using their free http://dev.mysql.com...ools/workbench/ tool.

I highly recommend putting your designs into a tool like this, and all the decent ones then offer the option of having them generate your DDL Sql to create the tables and indexes of your database which can save a lot of time and limit the iteration cycle inherent in design changes or simple mistakes.

The other tip I can offer in terms of mysql is to make sure you use the innodb engine for all your tables. Innodb turns on RDBMS standard features like referential integrity and ACID transaction support, and a transaction log that insures the integrity of your database in cases of catastrophic failure, and in most cases when you understand how to resource the database server properly, provides better performance.




Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com