...
  • Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp
KEEP IN TOUCH

Most Popular

  • osTickets > Reports v4.1 (11805)
  • HTPC > Setup Windows 7 as a Media Center with XBMC (6368)
  • osTicket > Auto-Assignment Rules (3602)
  • osTicket > View headers for original email message (2331)
  • Ubuntu 10.10 VNC Login Screen (2161)

Posts tagged php

WebDev > Allow PHP in WordPress Widgets

Jan26
2012
Leave a Comment Written by Scott Rowley

The following will allow for you to post PHP in your widgets:

Place in your functions.php file
Appearance > Editor > Theme Functions (functions.php)

add_filter('widget_text', 'php_text', 99);

function php_text($text) {
 if (strpos($text, '<' . '?') !== false) {
 ob_start();
 eval('?' . '>' . $text);
 $text = ob_get_contents();
 ob_end_clean();
 }
 return $text;
}

Now you can place php code so long as its within its <?php and ?> tags.
Credit

ajax loader
Posted in Web Development - Tagged allow, functions, theme, widget, wordpress
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Select first n words of a sentence

Jan16
2012
Leave a Comment Written by Scott Rowley

Useful for giving a teaser of a post and then including … on the end followed by “Read More”.

$sentence = "This is my sentence, there are many like it but this one is mine. What do you think of it?";
$n = 10; // Customize to however many words you want to actually show
$teaser = implode(' ', array_slice(explode(' ', $sentence), 0, $n));

echo $teaser."...READ MORE

Which should result in:
This is my sentence, there are many like it but…READ MORE

ajax loader
Posted in PHP, Web Development - Tagged array_slice, customize, echo, explode, implode, n, post, read more, sentence, teaser
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Keep your copyright date current automatically

Jan12
2012
Leave a Comment Written by Scott Rowley

Here’s a quick little tip I’ve been using recently with the new year having rolled around. I’ve started replacing all of my © 2011 code with the following. This will always return the date of the current year. That way you don’t have to remember to update it all over the place every time we “celebrate” a new year.

<?php echo date('Y'); ?>

So now I don’t ever have to update this post and the current year should always be reflected here: 2012

ajax loader
Posted in PHP, Web Development - Tagged automagically, automatic, automatically, copy, copyright, current, date, echo, year
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Populate PHP/HTML table from MySQL database

Jan11
2012
Leave a Comment Written by Scott Rowley

Hey again all, for this post I’ll be covering how to populate a PHP/HTML table by way of looping through a table in mysql. I’ll be using the sample database provided by http://www.mysqltutorial.org/mysql-sample-database.aspx which has to do with models (cars, planes, ships, etc). Everyone has differing levels of knowledge so I’ll be including some basics as well such as connecting to the mysql database (and closing it later on).

The table we’ll be using in the database is ‘products’. It has the following columns:

productCode        - A unique inventory number
productName        - Name of the product
productLine        - Basic descriptor, 'Motorcycles', 'Classic Cars', etc
productScale       - This models scale size
productVendor      - Company that built the model
productDescription - Detailed description of product
quantityInStock    - Current number of quantity in stock
buyPrice           - Listed price on the "website"
MSRP               - Manufacturers Suggested Retail Price

If I know I’m going to be using my mysql database in multiple files I’ll always throw the connection in something like a ‘dbconnect.php’ file. Here’s an example:

<?php
  mysql_connect("localhost", "MYSQL_USERNAME", "MYSQL_PASSWORD") or die(mysql_error());
  mysql_select_db("MYSQL_TABLE") or die(mysql_error());
?>

Now you can include this in every file, or better yet in your header file which will get included everywhere else. So for example in your header.php file you could throw in:

<?php
  require_once('dbconnect.php');
?>

Alright, so now you’ve got your connection to your database and the appropriate database selected. We’ll skip over the other content that you want to eventually add and say (for this example) that we want to list all of our models. We’ll look at doing this a few different ways, first off we’ll go simple and just request everything from the database and then we’ll tell php how to spit that all out to us.
READ MORE »

ajax loader
Posted in MySQL, PHP, Web Development - Tagged connect, html, limit, loop, MySQL, nest, nested, query, result, select, sql, where, while
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Validate Password creation with PHP

Dec06
2011
Leave a Comment Written by Scott Rowley

The following can be used to test for different criteria in passwords.

<?php

$min = 6;
$max = 20;
$password = $_POST['password'];
$confirmpw = $_POST['confirmpw'];

if($password != $confirmpw){
    $error .= "Password and Confirm password do not match! <br />";
}

if( strlen($password) < $min ) {
    $error .= "Password too short! <br />";
}

if( strlen($password) > $max ) {
    $error .= "Password too long! <br />";
}

if( !preg_match("#[0-9]+#", $password) ) {
    $error .= "Password must include at least one number! <br />";
}

if( !preg_match("#[a-z]+#", $password) ) {
    $error .= "Password must include at least one letter! <br />";
}

if( !preg_match("#[A-Z]+#", $password) ) {
    $error .= "Password must include at least one CAPITAL! <br />";
}

if( !preg_match("#\W+#", $password) ) {
    $error .= "Password must include at least one symbol! <br />";
}

if($error){
        echo "Password Failure: $error";
} else {
  // Code to execute on success.
}
?>
ajax loader
Posted in PHP, Security, Web Development - Tagged check, confirm, password, secure, security, validate, validation, verify
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

PHP > Export simple MySQL query to .csv file

Aug08
2011
Leave a Comment Written by Scott Rowley

The following will allow you to export your mysql queries from mysql to a csv file that can be opened in several spreadsheet softwares. You may need to change the , (comma) to a ; (semi-colon) depending on your software.

A note for those of you using my osTicket Reports MOD: This is not what I’m using for that.

<?php
$host = 'localhost';
$user = 'userName';
$pass = 'password';
$db = 'databaseName';
$table = 'tableName';
$file = 'export';

$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die("Can not connect.");

$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
 while ($row = mysql_fetch_assoc($result)) {
  $csv_output .= $row['Field'].", ";
  $i++;
 }
}
$csv_output .= "\n";

$values = mysql_query("SELECT * FROM ".$table."");
while ($rowr = mysql_fetch_row($values)) {
 for ($j=0;$j<$i;$j++) {
  $csv_output .= $rowr[$j].", ";
 }
 $csv_output .= "\n";
}

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
ajax loader
Posted in MySQL, PHP, Web Development - Tagged csv, dev, development, excel, export, file, libre, MySQL, office, open, web
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > PHP created random password

Jul22
2011
2 Comments Written by Scott Rowley
<?php

 // The letter l (lowercase L) and the number 1
 // have been removed, as they can be mistaken
 // for each other.

function RandomPass() {

    // Comment the first line to exclude special characters
    $chars  = "!@#$%^&*";
    $chars .= "abcdefghijkmnopqrstuvwxyz023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";  

    srand((double)microtime()*1000000);
    $i = 0;
    $pass = '' ;

    while ($i <= 7) {
        $num = rand() % strlen($chars);
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }

    return $pass;

}

// Usage
$password = RandomPass();
echo "Random password is: $password";

?>

ajax loader
Posted in Web Development - Tagged create, dev, development, microtime, password, rand, random, return, srand, substr, web, while
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

osTickets > Reports v4.1

Jun13
2011
227 Comments Written by Scott Rowley

Ok, so after being on the osTicket forum since July 2009 I’ve noticed that one big MOD that everyone wants and never fully gets is reporting. The following is my stab at it.

This MOD has been implemented and tested on 1.6ST and 1.6RC5, please let me know if you run into any issues.

Note: For version 3.3+ you will need to create a scp/reports folder (and make sure its writable by Apache) and place the image (csv.png) into the scp/images folder.

Requirements: MySQL 5

Note: Reports v2.4+ is compatible with Internet Explorer.

osTickets Reports osTickets Reports
osTickets Reports
READ MORE »

ajax loader
Posted in osTicket - Tagged date_add, date_format, date_sub, day, department, interval, mod, modification, month, MySQL, osTicket, report, reports, staff, year
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Password protect webpage(s) with PHP & LDAP

May27
2011
5 Comments Written by Scott Rowley

The title says it all, this will allow you to restrict the access to a page or pages running php with access to LDAP. I’ve used this a few times for some internal things we don’t want everyone getting access to or similar scenarios. As always if it works for you, please leave a comment and if it doesn’t please leave a question and I’ll see what I can do to help you out.

Enable LDAP

First thing you’ll need to do is to install ldap for php & enable the needed mods, ldap.load & authnz_ldap.load

On Ubuntu:

apt-get update
apt-get install php5-ldap
cd /etc/apache2/mods-enabled
ln -s ../mods-available/ldap.load ldap.load
ln -s ../mods-available/authnz_ldap.load authnz_ldap.load
apache2ctl graceful

READ MORE »

ajax loader
Posted in Ubuntu, Web Development - Tagged apache, apache2ctl, authnz_ldap.load, graceful, ldap, ldap.load, login, mods-available, mods-enabled, php5-ldap, restricted, secure, security
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

osTicket > Auto-Assignment Rules

Apr06
2011
36 Comments Written by Scott Rowley

The following is a MOD that I wanted to have for work and I noticed that several people have requested it in different threads on the forum over the years. This has been tested and is functional with 1.6RC5 AND 1.6ST

osTicket Auto-Assignment Rules

Purpose: Auto-assign tickets that are submitted via email based on their from address or Subject. If a ticket is assigned to a staff member it will automatically also be assigned to the department they are in.

READ MORE »

ajax loader
Posted in MySQL, osTicket - Tagged assign, auto, mod, modification, osTicket, ticket
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Older Entries

Be Heard!

Authors needed! Feel like sharing your tech wisdom with the world? We are looking to expand our writer base and would love to hear from you. We need articles on any relevant technology/software/media/howto/etc (Well...lets at least hold to the legal stuff ;)

Just email scott (at) sudobash (dot) net

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Sudo Bash Member sites

Des Moines, Iowa Karate Classes
Iowa MMA Tournaments
Iowa SAR

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

RSS HowToGeek

  • DIY Digital POV Clock On a Hard Drive Platter
  • How to Disable the Splash Screens in Office (Word, Excel, PowerPoint)
  • How To Resolve Dependencies While Compiling Software on Ubuntu
  • Version Tracking With Subversion (SVN) For Beginners
  • How to Set Up Email Notifications for Your Windows Home Server

RSS TheGeekStuff

  • How to Install GIT for Windows and Create / Clone Remote Repositories
  • 5 Practical Linux fuser Command Examples
  • Linux Memory Management – Virtual Memory and Demand Paging
  • XSS Attack Examples (Cross-Site Scripting Attacks)
  • 10 Things You (and Your Boss) Can Do To Change Your World

RSS LifeHacker

  • Remove Clothing Wrinkles with a Damp Towel [Clothes]
  • Factor in the Convenience Fee Before Charging Income Taxes to Your Credit Card [Taxes]
  • How to Block Annoying Tech Rumors and Movie Spoilers on Your Browser [Annoyances]
  • Use Plastic Shower Caps in the Kitchen to Cover Large Bowls and Leftovers [Clever Uses]
  • Twitter for iOS and Android Updates, Restores Swipe Gestures and Optimizes for Android Tablets [Updates]

EvoLve theme by Blogatize  •  Powered by WordPress Sudo Bash
By Geeks - For Geeks

Back to Top