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

Posts tagged php

Web Dev> Keep your copyright date current automatically

Jan12
2012
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: 2020

Posted in PHP, Web Development - Tagged automagically, automatic, automatically, copy, copyright, current, date, echo, year

Web Dev> Populate PHP/HTML table from MySQL database

Jan11
2012
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(DBHOST, DBUSER, DBPASS) or die(mysql_error());
mysql_select_db(DBNAME) 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 »

Posted in MySQL, PHP, Web Development - Tagged connect, html, limit, loop, MySQL, nest, nested, query, result, select, sql, where, while

Web Dev> Validate Password creation with PHP

Dec06
2011
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.
}
?>
Posted in PHP, Security, Web Development - Tagged check, confirm, password, secure, security, validate, validation, verify

PHP> Export simple MySQL query to .csv file

Aug08
2011
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."");
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;
?>
Posted in MySQL, PHP, Web Development - Tagged csv, dev, development, excel, export, file, libre, MySQL, office, open, web

Web Dev> PHP created random password

Jul22
2011
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 = 1;
$pass = '' ;
// Number of digits we'd like to have our password be
$n = 8;
while ($i < $n) {
$num = rand() % strlen($chars);
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
// Usage
$password = RandomPass();
echo "Random password is: $password";
?>
Posted in Web Development - Tagged create, dev, development, microtime, password, rand, random, return, srand, substr, web, while

osTickets> Reports v5.0

Jun13
2011
Written by Scott Rowley


IT’S HERE! REPORTS 6.0 FOR OSTICKET VERSION 1.7

NOTE: If you are running any versions from 2.3 to 4.1 the “Replies per Staff” report is WRONG. I strongly suggest you upgrade to 4.2+

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
pChart (for use with emailed reports) requires the GD and FreeType PHP extensions.

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

osTickets Reports osTickets Reports
osTickets Reports osTickets Reports
READ MORE »

Posted in MySQL, osTicket, PHP - Tagged date_add, date_format, date_sub, day, department, interval, mod, modification, month, MySQL, osTicket, report, reports, staff, year

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

May27
2011
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 »

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

osTicket> Auto-Assignment Rules

Apr06
2011
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 »

Posted in MySQL, osTicket - Tagged assign, auto, mod, modification, osTicket, ticket

Joomla> session.save_path error

Oct27
2010
Written by Scott Rowley

“Cookies do not appear to be enabled on your browser client. You will not be able to install the application with this feature disabled. Alternatively, there could also be a problem with the server’s session.save_path. If this is the case, please consult your hosting provider if you don’t know how to check or fix this yourself.”

Should you run into this problem the issue is likely that the session.save_path setting in php.ini is set to either an incorrect setting, a wrong permission on the folder, or no setting at all. If you have access to the servers php.ini file you can change the setting to something like the following:

session.save_path = /tmp

If you do not however, have access to this file then your next option is to use a .htaccess file (obviously you will then need to hope you are on an Apache server, not Windows/IIS). You can then enter this setting into your .htaccess file and achieve the same result. For instance:

php_value session.save_path "/isp/websites/sites/example.com/docs/tmp"
Posted in Joomla - Tagged error, Joomla, save_path, session
Newer Entries »

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

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top