[Skip to the main content] Welcome to Daigo’s Daily Digital Diorama. I blog about Baseball, Judo, Jazz, Linux, Design and on being a dad.

  • Get Firefox!

Webhosting problem

I really liked my web hosting company, till about two weeks ago. Then they messed it up. They messed it up bad… I was (am) very angry. My Database is screwed up, php was upgratded to 5 from 4 without notice so some of the scripts stopped functioning, worst of all, my e-mail domain was labeled spam, therefore not being able to get or send e-mail from my main account (thank god for gmail…).

So I went ahead and created new account at new hosting company, then started to move some of the sites. (I have way too many sites is one of the probelm…) but in this process I have learned (or re-learned) some of simple (but usuful) web related stuff, following is just a note to myself:

URL Rewrite

I wanted simply have /index.php?id=000000 (where 000000 is 6 digit numbers) to show up as /archive/000000 to the users. Create .htaccess file and put this in there

RewriteEngine on
RewriteRule ^archive/([0-9][0-9][0-9][0-9][0-9][0-9])$
index.php?id=$1

Related sites: Your HTML source, Hosting company wiki

PHP 5’s post/get data

You just need to have this in the bigining of the file:

<?php import_request_variables(g, "g_"); ?>

Now all your “Get” variable like index.php?id=12234&name=5678 can be accessed as $g_id and $g_name

Very simple form validator

In form with name=”sampleform”, have action=”/result.php” method=”post” onsubmit=”return validate()”. Say in this form you have name and comments and they are both required.


<script type="text/javascript">
<!–
function validate()
{
x=document.sampleForm
yourcomment=x.comments.value
yourname=x.name.value
  if (yourname.length<1)
   {
   alert(”Please enter your name”)
   return false
   }
  else if (yourcomment.length<1)
   {
   alert(”Please enter your comment”)
   return false
   }
  else
   {
   return true
   }
}

// –>
</script>

Simple caching mechanism for php

On one of my website, I had a query to mysql everytime user comes to the page, but I knew that the data only changes once a day. Those two sites really helped me oput: devshed php’s Output Caching with PHP, PHPit’s How to build a simple caching system, with PHP

Leave a Reply