1- Redirect whenever / wherever you want:
You cannot do this:
PHP Code:
<!doctype ..........>
<html>
<head>
</head>
<body>
< put here some header banner >
<?php
echo "something";
//check some POST variable and if it is not set goto some page:
header("Location: http://www.mysite.com/error.php");
This will give a Warning:"Cannot modify header information - headers already sent"
because you must put header() before any output in your code.
A simple workaround for this (for PHP 4+) is:
PHP Code:
<?php
ob_start();
?>
<!doctype ..........>
<html>
<head>
</head>
<body>
< put here some header banner >
<?php
echo "something"
header("Location: http://www.mysite.com/error.php");
?>
</html>
</body>
<?php
ob_end_flush();
Using
output_buffering will hold any output until you release them (flush). So you will be safe to use header() in anywhere in your code
2- Keep your database passwords safe
For this, you have to make some changes in your apache config file: httpd.conf, if you cannot access it, have your host do this for you.
BUT BE WARNED: make backups of everything, just in case you screw up

First, create a file with your usernames and passwords for databases, registrar APIs, control panel APIs, 3PP APIs etc. in it:
say, "secure.inc" file looks like this:
Code:
SetEnv DBASE_USER "username"
SetEnv DBASE_PW "password"
SetEnv ENOM_UID "enomuser"
SetEnv ENOM_PW "enompw"
And include this file into httpd.conf,
*INSIDE YOUR OWN VIRTUAL HOST BLOCK* or all users in the server can see it.
Code:
Include "/path/secure.inc"
Now restart you apache, and when you want to use those usernames and passwords you can call them as:
PHP Code:
conn_db = mysq_connect("localhost", $_SERVER["DBASE_USER"], $_SERVER["DBASE_PW"]);
So if even someone have your php code in someway, your passwords will not be exposed. But keep in mind, outputting
phpinfo() publicly will reveal your passwords.
3- heredoc usage
Consider this HTML code: (I know it has errors, I randomly deleted some parts. This is just an example)
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Untitled Document</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
</HEAD>
<BODY CLASS="sub">
<BR>
<TABLE WIDTH="90%" BORDER="0" CELLSPACING="2" CELLPADDING="4" STYLE="text-align: center">
H="90%" NOSHADE SIZE="1">
<BR>
<TABLE WIDTH="90%" BORDER="0" CELLSPACING="0" CELLPADDING="4" STYLE="text-align: center">
<TR>
<TD WIDTH="15%" STYLE="white-space: nowrap">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="2" CLASS="FooterColor">
<TR>
<TD> 2001 Lorem Ipsum Dolor <A HREF="#">Sic Amet</A> • <A HREF="#">Consectetur</A> </TD>
<TD STYLE="text-align: right"> <A HREF="#">Lorum</A> • <A HREF="#">Ipsum</A> • <A HREF="#">Dolor</A> • <A HREF="#">Sic Amet</A> • <A HREF="#">Consectetur</A> </TD>
</TR>
</TABLE>
</BODY>
</HTML>
Think that you want to put this code into a variable like $html_code.
You will have to take care of the all quotes and other characters you have to escape. And inserting some dynamic content inside it will be a nightmare.
Not exactly. We have
heredoc
check out this code:
PHP Code:
$html_code = <<< CONTENT
PUT ANYTHING HERE
I mean <anything>
<img src="img.gif">
<FORM ACTION = 'mypage.php'>
<DIV>
</DIV>
CONTENT;
heredoc will take care of everything for you. it starts with "<<<" follows a heredoc block identifier (CONTENT in this example). Ends with same block identifier name and a semicolon.
Heredoc ending block identifier must be at the most left side of the line. No space(s) or tab(s) before it. Identifier must include only alphanumeric characters and underscore. Must begin with a non-numeric character.
You want to use some dynamic content inside the block? No problem, use your php variables inside curly brackets:
PHP Code:
$html_code = <<< CONTENT
PUT ANYTHING HERE
I mean <anything>
http://www.{$domain}.{$tld}
<img src="{$img_name}.gif">
<FORM ACTION = 'mypage.php'>
<DIV>
{$staff->name["barney"]}
</DIV>
CONTENT;
Thats it for now, I hope you find these useful. I may come up with something more in near future.
Comments and corrections are welcome
