Site Sponsors:
PHP CRUD - New Project 
Decided to share this one:

https://sourceforge.net/projects/phpcrud/

Today many say that "CRUD" stands for "Create Retrieve Update and Delete." While fine for an SQL mindset, many old-timers got used to the acronym standing for "Create READ Update Delete" way back in the 1970's. Indeed, the term dates back even farther than ISAM. ...

By way of a handy completeness check-moniker however (the intended use?), the pattern works much the same for both camps. --The only difference is a record-oriented, rather than a QUERY oriented, mentality; Enjoying an expected result set of 1:1, -v- 1:*... or the difference between knowing what to expect, and perhaps having WAY too many (*) data coming back to process / secure effectively.

When designing software, be sure to know the difference. Why? Because while the classic 1:1 usage is easy and succinct, supporting the modern variant will imply many more activities. Discussions over things such as pre-queries, limiting queries, session limits, timeouts, roles, SQL injection attacks, view creation (etc.) invariably have to be considered. Activities that will consume not only design & implementation time, but data-processing resources, as well.

(Note: If you have followed a permalink to this article, then you will not have noticed a subsequent example. -Here is an interesting example.)

Enjoy,

-Rn

(*) Data is plural - Sounds odd, don't it? :)


[ add comment ] ( 4116 views )   |  permalink  |  related link
It's about time ..  
If you ever need a simple way to manage a sortable, logical, human-editable day & time representation, then I cobbled yet another one together from the com.soft9000.DateInfo and com.soft9000.TimeInfo classes this morning:


package com.soft9000.dates;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* TimeString24: A human-editable, sortable, 24-hour-clock-based time-format reader / writer.
*
* <p>The serialized date delimiter is "/", the time delimiter is ":".</p>
* <p>The ultimate representation is logic-sortable. Human-editable. 24-hour clock.</p>
* <p>Finally, because it is often desirable to put "garbage" into processed date fields,
* the use of &amp;Garbage-In Garbage-Out&amp; (Gigo) setters is supported
* for all individual fields. Note that a -1 in both the month and
* day areas is the isNull() condition.</p>
*
* (BC times, if used, COULD be <b>negative</b>?)
*
* @author profnagy
*/
public class TimeString24 {

private int Year = 0; // Gigo setter.
private int Month = -1; // 1 - 12. Gigo setter
private int Day = -1; // 1 - 31 (Gigo setter, user-specified days-in-month elsewhere are not strictly enforced)
private int Hour = 0; // 0 - 23. Gigo setter (only)
private int Minute = 0; // 0 - 59. Gigo setter (only)
private int Second = 0; // 0 - 59. Gigo setter (only)

/**
* isNull() construction.
*
*/
public TimeString24() {
super();
}

/**
* Create a time string from the classic Date type.
*
* @param date A java.util.Date
*/
public TimeString24(Date date) {
super();
assign(GetInfo(date));
}


/**
* Check to see if null construction was used.
*
* @return True of null construction values are used. False otherwise.
*/
public boolean isNull() {
return (Day == -1 && Month == -1);
}

/**
* Invalidate this object by putting null construction values back in-place.
*/
public void asNull() {
Day = Month = -1;
}

/**
* Assign the values for a date.
* @param Year The year
* @param iMonthNum The month
* @param Day The day
* @return True if all went well.
*/
public final boolean setDate(int iYear, int iMonthNum, int iDay) {
if (iMonthNum < 1 || iMonthNum > 12) {
return false;
}
if (iDay < 1 || iDay > 31) {
return false;
}
this.Year = iYear;
this.Month = iMonthNum;
this.Day = iDay;
return true;
}


/**
* Assign the values for a time.
* @param Hour The hour (24 hour clock)
* @param Minute The standard minute
* @param Second The standard second
* @return True if all went well.
*/
public final boolean setTime(int iHour, int iMinute, int iSecond) {
if (iHour < 0 || iHour > 23) {
return false;
}
if (iMinute < 0 || iMinute > 59) {
return false;
}
if (iSecond < 0 || iSecond > 59) {
return false;
}
this.Year = iHour;
this.Month = iMinute;
this.Day = iSecond;
return true;
}

/**
* Assign the values form a TimeString24.
*
* @param ref a TimeString24
* @return True if all went well.
*/
public final boolean assign(TimeString24 ref) {
if (ref != null) {
this.Second = ref.Second;
this.Minute = ref.Minute;
this.Hour = ref.Hour;
this.Day = ref.Day;
this.Month = ref.Month;
this.Year = ref.Year;
return true;
}
return false;
}

/**
* Pad-out an integer representation to the desired, sortable, size.
*
* @param iVal The integer
* @param minSize The file size (can be greater, will not be less)
* @return A string-parsable integer, as prefixed by '0' up-to the desired
* size.
*/
public static String Pad(int iVal, int minSize) {
if (minSize <= 0) {
minSize = 1;
}
boolean bNeg = false;
if (iVal == -1) {
bNeg = true;
minSize--; // negative sign will use a space -
iVal = java.lang.Math.abs(iVal);
}

StringBuilder sb = new StringBuilder();
sb.append(iVal);
if (sb.length() < minSize) {
int count = minSize - sb.length();
sb = new StringBuilder();
for (int ss = 0; ss < count; ss++) {
sb.append('0');
}
sb.append(iVal);
}
if (bNeg) {
String str = sb.toString();
sb = new StringBuilder();
sb.append("-");
sb.append(str);
}
return sb.toString();
}

/**
* Get the default "Date Only" string.
*
* @return YYY/MM/DD format
*/
public String adDateOnly() {
return (Pad(this.Year, 4) + "/" + Pad(this.Month, 2) + "/" + Pad(this.Day, 2));
}

/**
* Create a TimeString24() for the present second.
*
* @return An up-to-the-second TimeString24()
*/
public static TimeString24 GetToday() {
return GetInfo(GetDate());
}

/**
* Get today's Date
*
* @return Today's java.util.Date.
*/
public static Date GetDate() {
Calendar cal = new GregorianCalendar();
Date date = cal.getTime();
cal = null;
return date;
}

/**
* Create a TimeString24 from the classic Date type..
*
* @param date A classic Java Date type.
* @return Always returns a TimeString24.
*/
public static TimeString24 GetInfo(Date date) {
Calendar cal = new GregorianCalendar();
cal.setTime(date);
TimeString24 info = new TimeString24();
info.Year = cal.get(Calendar.YEAR);
info.Month = cal.get(Calendar.MONTH) + 1;
info.Day = cal.get(Calendar.DAY_OF_MONTH);
info.Hour = cal.get(Calendar.HOUR_OF_DAY);
info.Minute = cal.get(Calendar.MINUTE);
info.Second = cal.get(Calendar.SECOND);
cal = null;
return info;
}

/**
* Create a TimeString24 from the default toString() representation.
*
* @param sLine The toString() representation. The format is "2012/02/05
* 09:01:10"
* @return <font color='red'>NULL on error</font>.
*/
public static TimeString24 FromString(String sLine) {
if (sLine == null) {
return null;
}
TimeString24 result = new TimeString24();
if (result.fromString(sLine) == true) {
return result;
} else {
return null;
}
}

/**
* Format "2012/02/05 09:01:10"
*
* @return The parsable (fromString()) format.
*
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Pad(this.Year, 4));
sb.append("/");
sb.append(Pad(this.Month, 2));
sb.append("/");
sb.append(Pad(this.Day, 2));
sb.append(" ");
sb.append(Pad(this.Hour, 2));
sb.append(":");
sb.append(Pad(this.Minute, 2));
sb.append(":");
sb.append(Pad(this.Second, 2));
return sb.toString();
}

/**
* Format "2012/02/05 09:01:10"
*
* @param sLine The classic "ENGLISH STRING" to parse
* @return True on success
*/
public boolean fromString(String sLine) {
String str = sLine.replaceAll("/", "\t");
str = str.replaceAll(":", "\t");
str = str.replaceAll(" ", "\t");
String[] array = str.split("\t");

try {
if (array.length == 6) {
this.Year = Integer.parseInt(array[0]);
this.Month = Integer.parseInt(array[1]);
this.Day = Integer.parseInt(array[2]);
this.Hour = Integer.parseInt(array[3]);
this.Minute = Integer.parseInt(array[4]);
this.Second = Integer.parseInt(array[5]);
return true;
}

} catch (Exception ex) {
}
assign(new TimeString24()); // null
return false;
}

/**
* @return the Day
*/
public int getDay() {
return Day;
}

/**
* @return the Hour
*/
public int getHour() {
return Hour;
}

/**
* @return the Minute
*/
public int getMinute() {
return Minute;
}

/**
* @return the Month
*/
public int getMonth() {
return Month;
}

/**
* @return the Second
*/
public int getSecond() {
return Second;
}

/**
* @return the Year
*/
public int getYear() {
return Year;
}

/**
* @param Day the Day to set. Gigo
*/
public void setDay(int Day) {
this.Day = Day;
}

/**
* @param Hour the Hour to set. Gigo
*/
public void setHour(int Hour) {
this.Hour = Hour;
}

/**
* @param Minute the Minute to set. Gigo
*/
public void setMinute(int Minute) {
this.Minute = Minute;
}

/**
* @param Month the Month to set. Gigo
*/
public void setMonth(int Month) {
this.Month = Month;
}

/**
* @param Second the Second to set. Gigo
*/
public void setSecond(int Second) {
this.Second = Second;
}

/**
* @param Year the Year to set. Gigo
*/
public void setYear(int Year) {
this.Year = Year;
}
}


'Gotta love these quiet mornings!

-Rn


[ add comment ] ( 1289 views )   |  permalink  |  related link
Banman: An easy way to protect web content 
We just release a new project. Know as "Banman", the project is designed to stop robots from stealing web content.

Uploading the content of the zip file + renaming index_example.php to index.php will create a complete web site experience.

By default (*), logs are stored under the "ban_ip_list" folder. If logging does not seem to work & reports are not showing-up, then be sure to enable write-and-read access to whatever you change the banned.php::$dir_only_ip variable to.

(*) Since Banman is new, for the moment it would be relatively safe to use the default file & folder names. By all means run it a few times using the defaults.

After you decide to use the program, at a minimum consider changing both the name of the sub-folders, as well as the name the "banman.php" webmaster interface.

Also note that the variables listed in the default html view should also be changed. -While great for demonstrating what Banman can do, their values are set way too strict for most user-facing 'web applications.

Enjoy!

R.A. Nagy
President
Soft9000.com

[ add comment ] ( 2251 views )   |  permalink  |  related link

<<First <Back | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Next> Last>>