Bloggeh.com
BJJ, technology, psychology & other cool stuff
BJJ, technology, psychology & other cool stuff
Jan 19th
Generally speaking, the e-mail will go to junk because of incomplete and missing headers. Many spam filters pick these “lack of headers” as a commonality between all those e-mails for all those enlargement pills and pirated software we’ve all been after.
Your mail code is slightly incorrect though, generally speaking the usage for mail is:
mail(”To”,”Subject”,”Message”,”Headers”)
Which could explain why it went to junk the first time. Therefore you would have something like this established:
$headers = “MIME-Version: 1.0\r\n”;
$headers .= “Content-type: text/html; charset=iso-8859-1\r\n”; // Important to change if you ever add attachments
$headers .= “From: “.$email_address.”\r\n”;
$headers .= “Reply-To: “.$email_address.”\r\n”;
$headers .= “X-Mailer: PHP/”.phpversion().”\r\n”;
I’m sure you can work out the rest. Word of warning though, your e-mail address may be blacklisted as “junk” if you didn’t set the “from” value. There are many more headers that you may want to look up RFC2821 or some explanation on various headers.
Aug 25th
Coding Style – http://www.phpro.org/tutorials/PHP-Coding-Style.html
MVC – http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
OOP – http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html
Aug 24th
http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-1.php
http://www.php-mysql-tutorial.com/
http://www.phpro.org/tutorials/
http://www.idea22.com/video/list/
Aug 15th
http://www.corra.com.au/support/downloads/
# Australian Postcodes CSV File – Zip (292kb)
# Australian Postcodes MySQL Dump File – Gz (286kb)
# Australian Postcodes PHP Functions – Zip (2kb)
# Australian Postcodes PHP Functions – Plain Text (3kb)
# Australian Postcodes MySQL Function – Plain Text (1kb)
Jun 2nd
Two great articles
http://www.astahost.com/info.php/how-create-pdf-php_t4972.html
http://www.devarticles.com/c/a/PHP/Use-PHP-to-Create-Dynamic-pdf-Files/
Mar 18th
After completing the Lynda.com recent PHP and MySQL training series, these are the notes that I’ve taken. Hopefully they can serve as a useful reference for you like they have me!
Its better to use double quotes.
Single quotes will output the variable name.
|
$string = “The quick brown fox jumped over the lazy dog†|
|
|
.= |
Concatenates a string |
|
str_repeat($string,2); |
Repeats a string twice |
|
strpos($string,â€brownâ€); |
Finds the position of the string |
Increment: $var++
Decrement: $var–
Random number: rand()
Random number with min/max: rand(1,10)
Floating point numbers are Decimal numbers! Ie. 3.14
$myfloat = 3.143864
Round($myfloat,2); would produce 3.14
print_r($array) will display all variables in an array
if you surround it with <pre> </pre> tags it will display them nicely formatted.
in_array(needle,haystack) checks for an item in an array
Boolean means true or false, 1 or 0 (respectively).
Isset($variable) tests the Boolean state of a variable and returns true or false
empty($variable) is similar to the opposite of isset($var).However it will return TRUE for the value 0 in both integer and string format (also NULL).
Similar to variables however they do not change!
define(“MAX_WIDTHâ€, 980);
echo MAX_WIDTH;
When using if, and elseif statements, the final else will be the default if none of the if and elseif statements are true.
Use when you need to test one variable, instead of writing many if / else statements.
Make sure you use break in the code or it will continue to search through the conditions
Switch ($a) {
case 0:
echo “hiâ€;
break;
}
$count = 0
while ($count <= 10) {
echo $count;
$count++;
}
Same as while loops.
Format is:
for (initial, test, each) {statement;}
example: for ($count, $count <= 10; $count++) {echo $count . “<br />â€; }
This is how you use each value
foreach ($array as $value) { statement; }
You can also loop through key, value pairs
foreach ($array as $key => $value) {statement;}
To find the current position of the pointer in an array
current($array);
Move to the next position in an array
next($array);
Reset the pointer in an array
reset($array);
Using a while loop that moves the array pointer (similar to what you would do processing rows that are returned from a database)
$ages = array(4,8,15,22,29,33,52);
while ($age = current($ages)) { // this will loop while it can successfully assign an age from
statement;
next($ages);
}
function name($arguments) { statement; }
Variables defined within a function, act as if they only exist within the function.
If you define a variable using the global $var syntax, then it will pull in variables outside of the function, and also make them available outside the function.
If you want to pass a character such as an ampersand (&) or space, you can include php in the link to urlencode the characters. For example:
<a href=â€test.php?name=<?php echo urlencode(“david&â€) ?>&surname=maraâ€> Link </a>
You only need to encode when using GET. Not with POST.
If you want to dynamically create an entire link, use rawurlencode($string) for everything before the ? in a link, and urlencode($string) for everything after.
setcookie($name, $value, $expire);
Must come before ANY html, white space, tabs etc.. on a page.
Must come before ANY html, white space, tabs etc.. on a page.
Format:
header(header information);
How to write a page re-direct.
header(“Location: page.htmlâ€);
exit;
Output buffering basically means that you can store up all the information of the page, and send it in one hit. This allows you to have headers appear in the body text of a page. This kind of ‘convenience’ comes at this cost of performance.
You can enable Output Buffering in the PHP.ini file.
You can also enable it without editing the PHP.ini file. You can do it within PHP.
ob_start(); // has to appear before any HTML is output if we’re sending headers
ob_end_flush();
SELECT * FROM table WHERE column1 = ‘some_text’ ORDER BY column1, column2 ASC;
INSERT INTO table (column1, column2, column3) VALUES (val1, val2, val3);
Note: Strings must have single quotes ‘ around them.
UPDATE table SET column1 = ‘some_text’ WHERE id = 1;
mysql_affected_rows() will tell you how many rows were affected in the last update.
DELETE FROM table WHERE id = 1;
$connection = mysql_connect(”localhost”, “root”, “password”);
$db_select = mysql_select_db(”widget_corp”, $connection);
$result = mysql_query(”SELECT * FROM subjects”, $connection);
while ($row = mysql_fetch_array($result)) {
echo $row['menu_name'] . ” ” . $row['position'] . “<br />”;
}
mysql_close($connection);
Connects to a MySQL server
Selects a database
Used to query the database
You can echo mysql_error() to get the error returned by mysql
Close a MySQL connection
Retrieves the records in an array (can be accessed using associative keys)
Remember you have to loop through each record in the array.
Retrieves the number of record rows retrieved from a query
Shows the affected number of rows from a query
Escapes dangerous characters from entering your database
Tells you the last inserted ID.
Anything you output to the browser should go through htmlentities especially if it’s coming from a database where users have entered the data.
Converts any special characters to %lt; (html entities!)
strips all html tags from text. You can allow specific tags as required:
strip_tags($content, “<b><br><p><a>â€);
This would allow the bold, break, paragraph and link tags to be the only html formatting on this text.
nl2br($content); will preserve any ‘enters’ or new lines in the text entered by the user.
When structuring your query string to search if a username/password is correct in a database, do NOT select * information and return that. This is insecure and you do not need the password returned. Instead return perhaps the id and the username and any other information you will require.
Incorrect Auth Check:
$query = “SELECT * FROM users WHERE username = ‘{$username}’ AND hashed_password = ‘{$hashed_password}’”;
Correct Auth Check:
$query = “SELECT id, username FROM users WHERE username = ‘{$username}’ AND hashed_password = ‘{$hashed_password}’”;