July 26, 2007

0

How to Redirect Using PHP

PHPA simple PHP script could be use to redirect visitor from the page they entered to a different web page. There is lot of reason you may want to do this including:

  • You may have links that is no longer exists in your domain
  • You don't want anybody to browse your parent directory where you don't have any index page in it
  • Or maybe you may want to shorten your long url like TinyUrl.

Using this simple method, they can be seamlessly transfered to the new page without having to click a link to continue.

Why use PHP for redirecting?
Here's some reason on why we are using PHP for redirecting.
  • Users are redirected quickly and seamlessly
  • When using the 'Back' button, the user is taken to the last viewed page, not the redirect page
  • Works on all browsers
However, you have to make sure that your web host do support PHP in order to do this.

In this example, assuming Mikey want to redirect his visitor who go to his domain http://mikey.com to his blog Url which is at http://mikey.com/blog. What mikey have to do is simply create a text file in his parent folder and type this:

<?php
header( 'Location: http://mikey.com/blog' ) ;
?>

Then save the file as 'index.php'. Now, all visitors who go to http://mikey.com will be seamlessly redirected to http://mikey.com/blog. Isn't it easy? Enjoy programming and have fun!

Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy




July 12, 2007

38

How to Show and Hide Text in Blog Post

I would like to share on how to make a Show/Hide text in your blog post. I'm sorry if I didn't explain detail enough because I want to keep my post short as I'm in a hurry. However, you can read the detail explanation on Blogger Help.

In this example, I assume you have sub topics that you want to make it hidden until reader clicks on the headline. Without the show/hide trick, it would look like this...

Title One

This is the example text for title one.

Title Two

This is the example text for title two.

Title Three

This is the example text for title three.

Here's my step to do this... Firstly, edit your template and add the following code in the CSS area.


.posthidden {display:none}
.postshown {display:inline}

Then add the following javascript code on your blog template between the <head></head> tag.

<script type="text/Javascript"> 

function expandcollapse (postid) {

whichpost = document.getElementById(postid);

if (whichpost.className=="postshown") {
whichpost.className="posthidden";
}
else {
whichpost.className="postshown";
}
}
</script>

Now save your template and all you have to do in each post you want to have the expandable sub topic is to create unique id for each sub topics where the code will look like this:

<a href="javascript:expandcollapse('subtopic0001')">
<h4>Title One</h4></a>
<span class="posthidden" id="subtopic0001">
This is the example text for title one.</span>

<a href="javascript:expandcollapse('subtopic0002')">
<h4>Title Two</h4></a>
<span class="posthidden" id="subtopic0002">
This is the example text for title two.</span>

<a href="javascript:expandcollapse('subtopic0003')">
<h4>Title Three</h4></a>
<span class="posthidden" id="subtopic0003">
This is the example text for title three.</span>

And, here's the result...

Title One

This is the example text for title one. The long text is just an example that this area will automatically move the space down. Subscribe to coderstalk.blogspot.com for more free code from me. Or simply check me out for latest update soon.

Title Two

This is the example text for title two. Come on my friend, you can even hide images in here. Look at this...
ApOgEE Avatar

Title Three

This is the example text for title three.

That's all... Good luck and have a nice day!






Share This Article:


Bookmark This Article:
Feed Me Digg Technorati del.icio.us Best to Stumbleupon Reddit Blinklist Furl Spurl Yahoo Simpy