Archive for July, 2008

 

php introduction notes – part 2..

Jul 02, 2008 in php, Web

From

https://www6.software.ibm.com/developerworks/education/os-phptut1/section4.html

Functions

Creating a function

<?php

function checkPasswords($firstPass, $secondPass){

if ($firstPass == $secondPass) {
echo “<p>Passwords match. Thank you.</p>”;
} else {
echo “<p>Passwords don’t match. \
Please try again.</p>”;
}

}

?>

Returning a value

<?php
function validate($allSubmitted){

$message = “”;

if ($message == “”){
$message = “OK”;
}

return $message;

}

if (validate($_POST) == “OK”) {
echo “Thank you for registering!”;
} else {
echo “There was a problem with your registration..”;
}

?>

Including files

<?php
include(“top.txt”);
?>

<?php
include(“bottom.txt”);
?>

Requiring files

<?php

include(“top.txt”);
require(“scripts.txt”);
?>

Avoiding duplicates (includes)

<?php

include_once(“top.txt”);
require_once(“scripts.txt”);
?>

php introduction notes – part 1..

Jul 01, 2008 in php, Web

Basic things about php..

From

https://www6.software.ibm.com/developerworks/education/os-phptut1/index.html

Variables

A variable is a placeholder for data. You can assign a value to it, and from then on, any time PHP encounters your variable, it will use the value instead. For example, change your page to read:


<html>
<title>Workflow Registration</title>
<body>
<p>You entered:</p>

<?php
$username = “tyler”;
$password = “mypassword”;

echo “<p>Username = ” . $username . “</p>”;
echo “<p>Password = ” . $password . “</p>”;
?>

</body>
</html>

Constants

<?php
define(“PAGE_TITLE”, “Workflow Registration”);
?>

<html>
<title><?php= PAGE_TITLE ?></title>

Accessing form data

<body>
<p>You entered:</p>

<?php
$username = $_GET[‘name’];
$password = $_GET[‘pword’];

echo “<p>Username = ” . $username . “</p>”;
echo “<p>Password = ” . $password . “</p>”;
?>

</body>
</html>

Arrays


$formnames = array(“name”, “email”, “pword”);
echo “0=”.$formnames[0].”<br />”;
echo “1=”.$formnames[1].”<br />”;
echo “2=”.$formnames[2].”<br />”;

Notice that the first value has an index of 0, rather than 1. Notice also that you specified which value you wanted by adding the index in brackets after the name of the array variable. This action is similar to the way in which you access the form values, and that’s no accident. The $_GET variable is a special kind of an array called an associative array, which means that instead of a numeric index, each value has a key.

When you submit the form, you’re essentially creating an array like so:


$_GET = array(“name” => “roadnick”,
“email” => “ibmquestions@nicholaschase.com”,
“pword” => “supersecretpassword”);

Associative arrays

<?php
$form_names = array_keys($_GET);
$form_values = array_values($_GET);

echo “” . $form_names[0] . ” = ” . $form_values[0] . “”;
echo “” . $form_names[1] . ” = ” . $form_values[1] . “”;
echo “” . $form_names[2] . ” = ” . $form_values[2] . “”;
?>

For-next loop


for ($i = 0; $i < 10; $i++) { echo $i . " "; }


<?php
$form_names = array_keys($_GET);
$form_values = array_values($_GET);

for ($i = 0; $i < sizeof($_GET); $i++) {
echo “<p>”.$form_names[$i].” = ” . $form_values[$i] . “</p>”;
}
?>

Foreach loop

<?php
foreach ($_GET as $value) {
echo “<p>” . $value . “</p>”;
}
?>

<?php

foreach ($_GET as $key=>$value) {
echo “<p>”.$key.” = ” . $value . “</p>”;
}
?>

Using POST

<?php

foreach ($_POST as $key=>$value) {
echo “<p>”.$key.” = ” . $value . “</p>”;
}

$passwords = $_POST[“pword”];
echo “First password = “.$passwords[0];
echo “<br />”;
echo “Second password = “.$passwords[1];
?>

Crypto in php ..

Jul 01, 2008 in Cryptography, Security

Very useful article..


http://www.devx.com/webdev/Article/37821/0/page/1

A Guide to Cryptography in PHP
by Octavia Andreea Anghel

For every difficult and complicated 
question there is an answer 
that is simple, easily understood, 
and wrong. H.L. Mencken
string md5(string $str [, bool $raw_output ])

one-way encryption function.. useful for passwords..

string crypt (string $str [, string $salt ])
string sha1 (string $str [, bool $raw_output ])

php packages..

MCrypt
MHash   
Crypt_Blowfish  
Crypt_RSA       
Crypt_HMAC
Crypt_DiffieHellman

Ubuntu / Debian package management notes..

Jul 01, 2008 in Linux, Ubuntu

To manage packages in a shell, use these programs:

Set wide printing area:

export COLUMNS=128

dpkg, dpkg-query, dselect, apt-get

‘ dpkg -l ‘*’ ‘ (or dpkg –list ‘*’) is like ‘yum list’ on Fedora.

Check out


http://hawknotes.blogspot.com/2006_04_01_archive.html
for more details..

List installed packages: dpkg -l | rpm -qa

List all available packages: dpkg -l ‘*’ | yum list

List contents of package: dpkg -L package_name | rpm -ql package_name

Find the package that installed file: dpkg -S file | rpm -qf file

Install a package: apt-get install package_name | rpm -i package_name
(or yum install package_name)

Remove a package: dpkg –purge package_name | rpm -e package_name