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

Most Popular

  • osTickets > Reports v4.2 (18056)
  • HTPC > Setup Windows 7 as a Media Center with XBMC (10962)
  • osTicket > View headers for original email message (4173)
  • WebDev > Allow PHP in Wordpress Widgets (3615)
  • Web Dev > Password protect webpage(s) with PHP & LDAP (2475)

Posts in category Web Development

Web Dev > Use onFocus to clear a value and onBlur to replace empty values

Oct17
2011
Leave a Comment Written by Scott Rowley

The following can be used to clear a value. I regularly use this for website search bars.

<script type="text/javascript">
function blank(a) { if(a.value == a.defaultValue) a.value = ""; }
function unblank(a) { if(a.value == "") a.value = a.defaultValue; }
</script> 

<input type="text" value="email goes here" onfocus="blank(this)" onblur="unblank(this)" />

This post was updated using code found here, which I think works a little nicer.

ajax loader
Tagged clear, dev, development, html, Javascript, onclick, this, value, web
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 - Tagged csv, dev, development, excel, export, file, libre, MySQL, office, open, php, 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
Tagged create, dev, development, microtime, password, php, rand, random, return, srand, substr, web, while
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Joomla > Repair c99madshell hacked site

Jun07
2011
Leave a Comment Written by Scott Rowley

This is information on removing the c99madshell hack that can get into some Joomla 1.5 sites. Most of this content is an original article of News Blog. I was only able to find one portion of this myself before finding their article, kudos and thanks go to them.

If you see the following Joomla error appearing on most Joomla pages including admin section

File Not Found The requested URL was not found on this server
OR
If you have a list of spam links

then your installation has likely been compromised. There is a security bug in Joomla 1.5 allowing a hacker to reset your admin password.

You should take the following steps to get rid of the error message and secure your Joomla:
READ MORE »

ajax loader
Posted in Joomla - Tagged button.gif, c99madshell, file, found, hack, Joomla, not, response.php, spam, tw4x
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

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

May27
2011
7 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 - Tagged apache, apache2ctl, authnz_ldap.load, graceful, ldap, ldap.load, login, mods-available, mods-enabled, php, php5-ldap, restricted, secure, security
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Meta-Redirect

Apr27
2011
Leave a Comment Written by Scott Rowley

I keep forgetting this and I keep needing it – so I’m just finally going to make note of it here:

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">

The zero in this case is the amount of time before a reload (so if you wanted to you could say something like “This page is no longer here – redirecting you in 3 seconds” and then change it to a 3. This code needs to be placed within the <head> tags.

ajax loader
Tagged dev, development, meta, redirect, web
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Allow users to upload multiple files

Apr12
2011
Leave a Comment Written by Scott Rowley

In this particular example we are allowing users to upload up to 4 image files at a time (we will specify jpeg, jpg, gif, png, and bmp to be allowed). We will also restrict the size to less than 2mb (16777216 bits)

First we need the page containing our form for uploading the files:

file.php

<form enctype="multipart/form-data" action="upload.php" method="post">
Image1: <input name="file[]" type="file" /><br />
Image2: <input name="file[]" type="file" /><br />
Image3: <input name="file[]" type="file" /><br />
Image4: <input name="file[]" type="file" /><br />
<input type="submit" value="Upload" />
</form>

Now we need the file that will actually do all the work:

upload.php

<?php
  $success = 0;
  $fail = 0;
  $uploaddir = 'images/';
  for ($i=0;$i<4;$i++)
  {
   if($_FILES['file']['name'][$i])
   {
   // Allow only up to 2mb images
   if($_FILES['file']['size'][$i] < 16777216){
    $uploadfile = $uploaddir . basename($_FILES['file']['name'][$i]);
    $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
    if (preg_match("/(jpeg|jpg|gif|png|bmp)/",$ext))
    {
     if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $uploadfile))
     {
      echo " http://example.com/" . $uploadfile . "<br>";
      $success++;
     }
     else
     {
     echo "Error Uploading the file. Retry after sometime.\n";
     $fail++;
     }
    }
    else
    {
     $fail++;
    }
   }else{echo "Error uploading file, file is too large";
    $fail++;}
   }
  }
  if($success > 0){
  echo "<br>Number of files successfully uploaded: " . $success;
  }else{
  echo "<br>Number of files failed: " . $fail;
  }
?>
ajax loader
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > HTML form ‘Back’ button

Apr07
2011
Leave a Comment Written by Scott Rowley

It may be necessary at some point to send a user back to a previous page. This could be useful in cases such as errors or letting a customer review information and go back to change it.

<form><input type="button" value="Back" onClick="history.go(-1);return true;"></form>

The -1 indicates to go back a single page.

ajax loader
Tagged back, button, form, html
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Password protect apache directory with LDAP & .htaccess

Apr06
2011
Leave a Comment Written by Scott Rowley

First thing you’ll need to do is to enable the needed mods, ldap.load & authnz_ldap.load These come preloaded with most linux, you’ll just need to enable them.
On Ubuntu:

Enable LDAP Authentication

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

.htaccess

You should now be able to implement the following wherever desired:
Example .htaccess file

Order deny,allow
Deny from All
AuthName "Restricted Page - login with LDAP credentials"
AuthType Basic
AuthBasicProvider ldap
AuthzLDAPAuthoritative on
AuthLDAPUrl ldap://ldap.example.com/ou=admins,o=LDAPROOT?adminUser
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
Require valid-user
Satisfy any

<Files .htaccess>
order allow,deny
deny from all
</Files>

Note that ‘?adminUser’ on the end of the AuthLDAPUrl line is whatever object you use in your configuration.

Apache Config

/etc/apache2/sites-available/default
Make sure the following is set (the default is AllowOverride AuthConfig)

AllowOverride All
ajax loader
Posted in Ubuntu - Tagged htaccess, ldap, password, protect, security, ubuntu
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail

Web Dev > Force users from http to https

Apr05
2011
Leave a Comment Written by Scott Rowley

Tested and verified working for *nix servers:

Add the following to your .htaccess file in the root of your website:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI}

I don’t work with IIS so check the following link for information on setting up the redirect on IIS servers:
http://www.sslshopper.com/iis7-redirect-http-to-https.html

ajax loader
Posted in Ubuntu, Windows - Tagged apache, follow, force, htaccess, http, https, IIS, nix, options, rewrite, server, symlinks, user
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Older Entries Newer 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
Ooo-er
5point Studios Tattoo & Piercing

Meta

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

RSS HowToGeek

  • Week in Geek: Aero Glass Feature will be Removed from Windows 8
  • How to Speed Up Web Browsing with Search & Bookmark Keywords
  • Geek Trivia: Pagers Were First Developed To Assist Which Professionals?
  • The Best Tips and Tricks for Using Email Efficiently
  • Desktop Fun: Starry Skies Wallpaper Collection Series 2

RSS TheGeekStuff

  • UNIX / Linux Processes: C fork() Function
  • How to Calculate IP Header Checksum (With an Example)
  • How to Encrypt Your Bash Shell Script on Linux Using SHC
  • Intro to DOCSIS Architecture, CM CMTS Protocol for Cable Modems
  • Ettercap Tutorial: DNS Spoofing & ARP Poisoning Examples

RSS LifeHacker

  • DIY Maple-Flavored Pancake Syrup [Breakfast]
  • This Week's Top Downloads [Download Roundup]
  • Make Mini Dutch Baby Pancakes in a Muffin Tin [Breakfast]
  • Pour Vinegar Down Your Drain Every Three Months to Keep Clogs Away [Video]
  • Use the Jelly Pocket Method for a Better Drip-Free PB&J [Food Hacks]

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

Back to Top