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

Posts tagged development

WebDev> Fixing Warning: “Headers already sent” & “Cannot modify header information”

Mar24
2012
Written by Scott Rowley

Eventually in your web development you may run into one of these annoying errors. What it typically means is that your browser is being sent some HTML before the PHP command header() and it’s causing your issue.

Unfortunately there is no easy way to go about troubleshooting this other than following the logic through your code, hopefully you’ve saved & tested recently and have a fairly short code to go troubleshooting with. In video games I learned early on to “Save early, save often”. I’ve since modified that to my programming so that I remember to save early, save often but also “Test early, test often”. Make little changes, then you know how much you need to go back and troubleshoot when there is an error. Anyway, another less known cause of this issue is that you’ve got the dos character ^M inserted in your code. This recently happened to me when I used FTP to download a website and then uploaded it somewhere else. Somewhere along the line my windows PC decided my perfectly fine files should have some ^M inserted into some of the files. As a result I got the “Headers already sent” error.

I’d run into the error before but I knew that I hadn’t introduced any new code so I knew it couldn’t be any html being sent before the header() function. After much googling and “facedesk”‘ing I finally found that the dos character could also cause this error. After a bit more googling I found that the easiest way to get rid of this is to simply run the following command and it will easily and quickly remove all of the dos characters (^M).

dos2unix your_messed_up_file.php

I ran this command on the file and then tried my test again and just like that I was back to normal again 🙂

Posted in Web Development - Tagged already, cannot, dos2unix, fix, fixed, fixing, headers, information, modify, php, save, sent, test, troubleshoot, warning, web

WebDev> CSS Stylings

Jan25
2012
Written by Scott Rowley

Just starting to make a note of some of my CSS creations:

Informational Box

SudoBash is proud to announce our newest office location

123 Kittens Street conveniently located 1 mile from LOLcat lane.

<style>
.info {
border: 2px solid #D8D8D8;
margin: 10px 0px;
background-repeat: no-repeat;
padding: 10px 0 10px 150px;
background-position: 10px center;
color: #00529B;
background-color: #E0E0E0;
background-image: url('/images/info.png');
}
</style>
<div class="info"><strong>SudoBash is proud to announce our newest office location</strong><br><br>
123 Kittens Street conveniently located 1 mile from LOLcat lane.</div>
Posted in Web Development - Tagged css, dev, html, info, information, web, Web Development

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

Oct17
2011
Written by Scott Rowley

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

<script>
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.

Posted in Web Development - Tagged clear, dev, html, Javascript, onclick, this, value, web

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, excel, export, file, libre, MySQL, office, open, php, 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, microtime, password, php, rand, random, return, srand, substr, web, while

Web Dev> Meta-Redirect

Apr27
2011
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.

Posted in Web Development - Tagged dev, meta, redirect, web

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