23 December 2010

how to use redirect using Javascript

javascript
Redirects are useful when doing some work and needs to go to another page after finished the work.

For example : after showing successful login , you will be redirected to home page.

Using button as link using javascript inside HTML code:

<input type="button" value="Visit Google" onclick="window.location = 'http://www.google.com' "/>

Use one line code to redirect :

 window.location = "http://www.google.com" ;


Note: The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page.

(If you found this article useful then share with your friends.)

how to get input value using javascript

javascript
Using only javascript and html,  we can get data from input box. using
document.getElementById('web').value
where, web = id of the input text box.

Sample code that use javascript to get input value:

[Note : Paste this code inside the <body> tag. to work.]

<script type="text/javascript">
function visit()
{
    var t = document.getElementById('web').value ;
    alert( t );
   
}
</script>

Enter Web Address: <input type="text" name="web" id="web"/>
<input type="button" value="Show what is in this Text Box" onclick='show();'/>


(If you found this article useful then share with your friends.)

How to use PHP bot to get Wikipedia definitions

php
This code helps to parse wikipedia definitions on given keyword.
Here is a code given that parse webpage using php with Curl extension.
A function is given which takes the keyword as input and outputs the array which holds the data.
$url : Holds the link to be parsed.

File name : wiki_parse.php
<?php
//FUNCTION THAT :PARAMETER - KEYWORD , AND RETURNS WIKI DEFINITION (IN ARRAY FORMAT)
function wikidefinition($s) {
//ENGLISH WIKI
    $url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=".urlencode($s)."&format=xml&limit=1";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
    curl_setopt($ch, CURLOPT_POST, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);
    curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
    curl_setopt($ch, CURLOPT_REFERER, "");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
   
    $page = curl_exec($ch);
    $xml = simplexml_load_string($page);
    if((string)$xml->Section->Item->Description) {
        return array((string)$xml->Section->Item->Text,
                     (string)$xml->Section->Item->Description,
                     (string)$xml->Section->Item->Url);
    } else {
        return "";
    }
}
//END OF FUNCTION WIKIDEFINITIONS



//USE OF FUNCTION
$data = wikidefinition('Bangladesh') ;
//var_dump( wikidefinition('bangladesh') ) ; //displays the array content
echo "Word:"       . $data[0] . "<br/>";
echo "Definition:" . $data[1]  . "<br/>";
echo "Link:"       . $data[2] . "<br/>";

?>

Thanks to barattalo.it

(If you found this article useful then share with your friends.)

04 November 2010

Set Folder Name to be working as Primary Domain Name

To make a new folder as the default domain name , you need to write some code in .htaccess file

For example :
if your domain name is www.yourweb,com
and you want to set a folder named ver1 as primary directory ,
then you need to write some code in .htaccess file to redirect to your ver1 folder as primary domain.

To do this , create a file names .htaccess in the public_html/ directory .
Write the following code in .htaccess file .
Change <DOMAIN> to your domain name .
Change <SUBDIRECTORY> to the path of that folder you like to set to be primary directory.

-------------------------------------------------------------------------------------
.htaccess
-------------------------------------------------------------------------------------
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} <DOMAIN>
RewriteCond %{REQUEST_URI} !^/<SUBDIRECTORY>/(.*) [NC]
RewriteRule ^(.*)$ /<SUBDIRECTORY>/$1
-------------------------------------------------------------------------------------


This code after changing will look like this :
-------------------------------------------------------------------------------------
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www.yourWebsite.com
RewriteCond %{REQUEST_URI} !^/ver1/(.*) [NC]
RewriteRule ^(.*)$ /ver1/$1
-------------------------------------------------------------------------------------

(If you found this article useful then share with your friends.)

03 November 2010

Changing the title of the page in joomla

joomla
To change the Title of the page viewed on the top of the browser, you need to follow this steps:
  1. Go to Admin of Joomla ,
  2. Browse Menus , then Main Main ,
  3. Select Home
  4. Look for tab : Parameters System
  5. Under the title : Page Title , write your desired title.
Done .

For more information, visit Joomla.org

(If you found this article useful then share with your friends.)

29 October 2010

How to access controller file directly without index.php in CodeIgnitor

code ignitor
To access controller file in codeIgnitor Framework directly without index.php as prefix, you need to create .htaccess file in your root directory.

Write the following lines in .htaccess file :

------------------------------------------------------------------------------------------
.htaccess
------------------------------------------------------------------------------------------

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

--------------------------------------------------------------------------------------------

Note: If you cannot create .htaccess file in Windows OS then read this Post :

(If you found this article useful then share with your friends.)

How to Create .htaccess file in Windows OS ?

While creating a file manually with .htaccess , it gives a warning and says "You must type a file name" . So to create .htaccess file in Windows OS ,you need to follow this:
    htaccess
  1. Go to Start -> Run -> Type "notepad" and click OK.
  2. Write your code for .htaccess.After finish writing, go to File -> Save As
  3. Enter file name .htaccess
  4. Choose Save as type: All files
  5. click Save .
Done.



(If you found this article useful then share with your friends.)

24 October 2010

Some useful PHP MYSQL functions

php
PHP MYSQL functions helps to connect to the database in MySQL software.
These are some of the most frequently used function names :


mysql_connect — Open a connection to a MySQL Server

mysql_create_db — Create a MySQL database

mysql_error — Returns the text of the error message from previous MySQL operation

mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both

mysql_num_rows — Get number of rows in result

mysql_query — Send a MySQL query

mysql_tablename — Get table name of field

mysql_close — Close MySQL connection

(If you found this article useful then share with your friends.)

23 October 2010

File structure of custom joomla template

joomla
To create your own template in joomla , you need to create to follow file structure .
  1. templateDetails.xml
  2. index.php

-----------------------------------------------------------------
1. index.php
-----------------------------------------------------------------
<html>
<head>
<jdoc:include type="head" />
</head>
<body>
<jdoc:include type="message" />
<div class="center" align="center">Welcome to your own template</div>
<jdoc:include type="modules" name="debug" />
</body>
</html>

-----------------------------------------------------------------


-----------------------------------------------------------------
2. templateDetails.xml
-----------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="template">
<name>Name of the Template - zahid template</name>
<description>
This will be your first joomla template
</description>
<files>
<filename>index.php</filename>
<filename>templateDetails.xml</filename>
</files>
</install>

-----------------------------------------------------------------

After creating this two files , place it in a folder and copy this folder to the template folder inside the joomla folder.
  • Go to your joomla site administrator panel.
  • Go to Extensions -> Template Manager
  • Choose on the radio button of your newly created template and select Default button to active the template .
  • Go to the site or click Preview to see the results.

(If you found this article useful then share with your friends.)