*a constant parallactic paradox, sublime*

Author Archive

Useful PHP Functions

These are three of my favorite PHP functions. πŸ˜€

string file_get_contents ( string $filename [, int $flags [, resource $context [, int $offset [, int $maxlen ]]]] )Get the contents of a url.

Example:

// following code will display the contents of the web page http://www.example.com
$url = “http://www.example.com”;
$contents = file_get_contents($url);
echo $contents;

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )Requires an email server. This functions programatically sends an email based on the given parameters.
Example:

// send an email to someone@somedomain.com
$to=”someone@somedomain.com
$subj = “example”;
$message=”this is an email”;
if(mail($to, $subj, $message)) echo “Email was sent”;
else echo “Email sending failed.”;

int fwrite ( resource $handle , string $string [, int $length ] ) Write something to a file. Note that the file and it’s parent directory should have permissions granted to a user such as “apache” or “www-data”.

Example:

// open a file called test.txt and if it does not exist, attempt to create it; place the pointer at the begining of the file
$handle = fopen(“test.txt”, “a+”);
$data = “I am programatically written.\n”;
fwrite($handle, $data);
fclose($handle);

I’ll stick with these 3 functions for the meantime. With this though, you can make programs such as:

  • A simple email interface. πŸ˜€
  • A logging system using just the last function
  • A proxy browser or something.

PHP SESSION

This post was originally titled "PHP Developer Essentials" which was what I really wanted to post instead of "PHP Essentials". But as I was at it, I got really bored and I realize, I really just wanted to list all my favorite or let me just say "mostly used" php functions.

But to preserve the efforts, let me just leave what I have already typed here—Creating a session with PHP.

Creating a Session

login.php

<?php
$login_name = $_POST[‘username’];
$login_password = $_POST[‘password’];
if($login_name==’admin’ && $login_password==’@dm!n’){
   session_start();
   session_cache_expire(15);
   $_SESSION[‘user’] = $_POST[‘username’];
   header("Location: ‘home.html’");
}
else{
   die("Authentication Failed");
}
?>

What this simple program does, is get post data from a form that uses the POST method and defined the URL of this code as the form target. The form will look like:

<form action=’login.php’ method=’post’>
Username: <input type=’text’ name=’username’>
Password: <input type=’password’ name=’password’>
<input type=’submit’ value=’Login’>

After retrieving post data, it will validate the user inputs then start a session and store the login data (username) in a session variable called (user). It will then set the window location to the home page using the header() function.



PHP Essentials

Learn PHP quick! Here are the php elements and functions which I find essential in developing applications with PHP.

Basic Syntax

<?php
echo “hello world”;
?>

The output would be:

hello world

Variables

Variables are represented by a dollar sign ($) and does not require type declaration.

<?php
$a = “this is a string”;
$b = 1;
$c = 2;
$d = $b + $c;
echo $d . ” is an integer” . “<br>”;
echo $a;
?>

The output would be:

3 is an integer

this is a string

Basic Conditions

Here are some of the most basic conditions:

<?php
$a = 1;
$b = 2;
if($a==$b){
echo “a is equal to b” . “<br>”;
}
else if($a!=$b){
echo “a is not equal to b” . “<br>”;
}
if($a>=$b) or $a==1){
echo “a is greater than or equal to b or a is equal to 1”;
}
?>

The output would be:

a is not equal to be
a is greater than or equal to b or a is equal to 1

….Anyway, this is supposed to be a reference, not a tutorial. To really learn php, go to this site!


PARADOX

I curse blindness for being the only one who saw

I curse sweetness for being bitter the most

I curse fortitude that brought me to my fall

And I curse softness that inflicted crooked stillness,

Who inflicted pestilence, fierce and massive

I curse reality for being so fake

And I curse curses for cursing back at me

To end up desolate for what I’m fed up with…

To claim victory over my own defeat…

To wake up still in perennial slumber,

Drifting off to surrealism wide awake…

To think of thinking when the mind has only emptiness

All to end up knowing that you do not know

(I omitted the last lines!)

I am the true author of this poem. Paradox was first published in Heraldo Filipino, the Official Publication of De La Salle University – Dasmarinas (DLSU-D) Palad vol.4. Credits are at the back part of the booklet where you will find my name as author to this poem and many others. To those who have plagiarized it, stop faking your poor soul or you’ll never grow!

In the link below, I have found a post titled “Paradox on a Summer” which contains half of my “Paradox” and half of another poem of mine called “Quarry” :
THE DEVIL

More proof of this authorship? Ask the Lasallians! These are are archived in the DLSU-D Library. Checkout the list of most of my published articles in My Heraldo Filipino Articles.

ONE MORE PLAGIARIZER I’VE DISCOVERED:


PLAGIARIZER

Her Friendster Profile which, if this URL has changed, means she had already acted on her guilt. (X_+)

View Image of the poor soul…