Header menu

_________________________________________________________________________________

Friday 30 August 2013

Send value of checked checkboxes on next page

<html>
    <body>
<?php
if($_POST){

    echo "<pre>";
    print_r($_POST['test']);
    echo "</pre>";
    }
?>
<form action="#" method="post">
<input type="checkbox" name="test[]"  value="Test1">Test1<br>
<input type="checkbox" name="test[]"  value="Test2">Test2 <br>
<input type="checkbox" name="test[]"  value="Test3">Test3<br>
<input type="checkbox" name="test[]"  value="Test4">Test4 <br>
<input type="submit" name="submit">
</form>
<body>
 <html>

Thursday 29 August 2013

Paging in php

To implement paging we need 3 things :
1. php code
2. css file
3. database

So first create a database with name paging (you can take any name but this is the name i am taking ).
Then create a table with name tb_page with 3 fields (id , title , description).


Then go to link below and download 3 files and save them with same name in your root directory ..
Download link :  https://gist.github.com/codesplanet/6386348

Note : Dont forget to change your host name , user name and password of database in pagination.php file ..


Tuesday 27 August 2013

Add link in an image in html

<html>
<body>
<div style="border:1px solid; background-color:#EDEDED; height:auto ;width:320px;">
    <div style="background-color:#666683; height:30px ;width:320px;">
        <b><p style=" text-color:#ffffff;align=:center; margin: 0 70;">Web Coding Source </p></b>
        </div>
<a href="http://codesplanet.blogspot.com/"><img border="1px" width="318px" height="250px" src="http://2.bp.blogspot.com/-7-FF9WY6NLA/Uhn7osnYiXI/AAAAAAAAAEw/qIgAg3EFBjU/s1600/apache-mysql-php-phpmyadmin-300x187.jpg"/></a>
</div>
</body>
</html>

How to convert a string to array in jquery ?

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
    $( document ).on("click",function(){
        var data="hello bro ..  how are you ??";
        alert('This is string : '+ data);
        var array_data=data.split(" ");
        alert("This is converted array : "+jQuery.each(array_data, function(index, value) {}));
});
});
</script>
</head>
<body>
converting  string to array in jquery ... on mouse click ..
</body>
</html>

Monday 26 August 2013

How to design a basic joomla template ?

File Structure : (to be saved in template directory of joomla)

-------------------------------------------------------------------------------------------------
mytemplate(Folder)
                  -->index.php
                  -->template.xml
                  -->css(Folder)
                                ---> style.css
-------------------------------------------------------------------------------------------------

index.php

<html>
    <head>
        <jdoc:include type="head" />
        <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/style.css" type="text/css" />
    </head>
    <body>
        Hello !!.. This is a testing template
        <jdoc:include type="modules" name="top" />
        <jdoc:include type="component" />
        <jdoc:include type="modules" name="bottom" />
    </body>
</html> 

template.xml 

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="template">
        <name>mynewtemplate</name>
        <creationDate>2013-08-27</creationDate>
        <author>Amit kumar</author>
        <authorEmail>ak221189@gmail.com</authorEmail>
        <authorUrl>http://codesplanet.blogspot.com</authorUrl>
        <description>My New Template</description>
        <files>
                <filename>index.php</filename>
                <filename>template.xml</filename>
                <folder>images</folder>
                <folder>css</folder>
        </files>
        <positions>
                <position>breadcrumb</position>
                <position>left</position>
                <position>right</position>
                <position>footer</position>
        </positions>
</extension>

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


Now for joomla version 2.5 ,
1. go to extension(in admin panel)
2. click on extension manager
3. click on discover tab
4. click on discover button
5. now select your template and click install.

:) Happy coding

 







 

How to disable checkbox set using jquery ?

If you got two set of checkboxes and you have to use one at a time ... then using this code when you click on either of checkbox set .. the other will get disabled..



<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
    $( document ).on("click",function(){
        if($("input[name='test[]']:checked").val()){
        $('input:checkbox[name="test_2\[\]"]').attr('disabled', true);
        }
        if($("input[name='test_2[]']:checked").val()){
        $('input:checkbox[name="test\[\]"]').attr('disabled', true);
        }
        });
});
</script>
</head>
<body>


<form id="test_form">
    <b> Checkboxes1</b><br>
<input type="checkbox" name="test[]"   value="Test1">Test1<br>
<input type="checkbox" name="test[]"  value="Test2">Test2 <br>
<input type="checkbox" name="test[]"   value="Test3">Test3<br>
<input type="checkbox" name="test[]"  value="Test4">Test4 <br>
<b> Checkboxes2</b><br>
<input type="checkbox" name="test_2[]"   value="Test1">Test1<br>
<input type="checkbox" name="test_2[]"  value="Test2">Test2 <br>
<input type="checkbox" name="test_2[]"   value="Test3">Test3<br>
<input type="checkbox" name="test_2[]"  value="Test4">Test4 <br>
</form>

</body>
</html>

Sunday 25 August 2013

How to get value of clicked checkbox using name in jquery ?

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){
    $( document ).on("click",function(){
        if($("input[name='test[]']:checked").val()){
        alert($("input[name='test[]']:checked").val());}
        });
});
</script>
</head>
<body>
<b> Checkboxes</b><br>

<form id="test_form">
<input type="checkbox" name="test[]"   value="Test1">Test1<br>
<input type="checkbox" name="test[]"  value="Test2">Test2 <br>
<input type="checkbox" name="test[]"   value="Test3">Test3<br>
<input type="checkbox" name="test[]"  value="Test4">Test4 <br>
</form>

</body>
</html>

Friday 23 August 2013

How to sort an array in php ?


<html>
<head>
<title>
Sorting an array in php
</title>
</head>
<body>
<?php
$arr=array("Rahul","George","tina","Angel");
echo "Array before sorting"."</br>";
echo "<pre>";
print_r($arr);
echo "</pre>";
sort($arr);
echo "Array After sorting"."</br>";
echo "<pre>";
print_r($arr);
echo "</pre>";
?>
</body>
</html>

Thursday 22 August 2013

How to add border in html div ?

Notice : solid in border

<html>
    <head>
        <title>
        Form
        </title>
    </head>
    <body>
        <div   align="center" style="border:1px solid ; background-color:#EA2343; height:400; width:700px;margin:0 auto;">
            Test
        </div>
    </body>
</html>

Align html div to center of page

<html>
    <head>
        <title>
        Form
        </title>
    </head>
    <body>
        <div   align="center" style="background-color:#EA2343; height:400; width:700px;margin:0 auto;">
            Test
        </div>
    </body>
</html>

How to convert a string into array in php ?

<?php
$str="Example";
$arr=array();
$arr=str_split($str);
echo "<pre>";
print_r($arr);
echo "</pre>";
?>

Wednesday 21 August 2013

How to send an array in url in php ?

File.php  (This file contain array )

<?php

$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'script');

$arr=http_build_query($data);

?>
<a href="nextpage.php?<?php echo $arr; ?>">Sendarray</a>


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

nextpage.php (This file will receive array and print it)


<?php
echo "<pre>";
print_r($_GET);
echo "</pre>";
?>

How to read a file character by character in php ?

<?php

$file=fopen("filename.txt","r") or exit("Unable to open file!");
while (!feof($file))
  {
  echo fgetc($file);
  }
fclose($file);

?>

Use linkedin api to fetch contact information in php ..

First Register your domain for linkedin api .

Then get your API_KEY, API_SECRET REDIRECT_URI , SCOPE ...

Run the script .. Njoy :)
------------------------------------------------------------------------------------------------------------------------
<?php

// Change these
define('API_KEY',      ' '          );  /*put API_KEY between '  ' */
define('API_SECRET',   ' '      ); /*put between API_SECRET '  '*/
define('REDIRECT_URI', ' '); /*put REDIRECT_URI between '  '*/
define('SCOPE',        ' '     ); /*put Scope between '  '*/


session_name('linkedin');
session_start();
$_SESSION['state']="India" // Name the country you live in
;
// OAuth 2 Control Flow
if (isset($_GET['error'])) {
    // LinkedIn returned an error
    print $_GET['error'] . ': ' . $_GET['error_description'];
    exit;
} elseif (isset($_GET['code'])) {
    // User authorized your application
    if ($_SESSION['state'] == "India") {
        // Get token so you can make API calls
        getAccessToken();
    } else {
        // CSRF attack? Or did you mix up your states?
        exit;
    }
} else {
    if ((empty($_SESSION['expires_at'])) || (time() > $_SESSION['expires_at'])) {
        // Token has expired, clear the state
        $_SESSION = array();
    }
    if (empty($_SESSION['access_token'])) {
        // Start authorization process
        getAuthorizationCode();
    }
}

// Congratulations! You have a valid token. Now fetch your profile by defining field you wanted

$user = fetch('GET', '/v1/people/~:(id,firstName,lastName,skills,location,industry,network)');
echo "<pre>";
print_r($user);
echo "<pre>";
exit;

function getAuthorizationCode() {
    $params = array('response_type' => 'code',
                    'client_id' => API_KEY,
                    'scope' => SCOPE,
                    'state' => uniqid('', true), // unique long string
                    'redirect_uri' => REDIRECT_URI,
              );

    // Authentication request
    $url = 'https://www.linkedin.com/uas/oauth2/authorization?' . http_build_query($params);
   
    // Needed to identify request when it returns to us
    $_SESSION['state'] = $params['state'];

    // Redirect user to authenticate
    header("Location: $url");
    exit;
}
   
function getAccessToken() {
    $params = array('grant_type' => 'authorization_code',
                    'client_id' => API_KEY,
                    'client_secret' => API_SECRET,
                    'code' => $_GET['code'],
                    'redirect_uri' => REDIRECT_URI,
              );
   
    // Access Token request
    $url = 'https://www.linkedin.com/uas/oauth2/accessToken?' . http_build_query($params);
   
    // Tell streams to make a POST request
    $context = stream_context_create(
                    array('http' =>
                        array('method' => 'POST',
                        )
                    )
                );

    // Retrieve access token information
    $response = file_get_contents($url, false, $context);

    // Native PHP object, please
    $token = json_decode($response);

    // Store access token and expiration time
    $_SESSION['access_token'] = $token->access_token; // guard this!
    $_SESSION['expires_in']   = $token->expires_in; // relative time (in seconds)
    $_SESSION['expires_at']   = time() + $_SESSION['expires_in']; // absolute time
   
    return true;
}

function fetch($method, $resource, $body = '') {
    $params = array('oauth2_access_token' => $_SESSION['access_token'],
                    'format' => 'json',
              );
   
    // Need to use HTTPS
    $url = 'https://api.linkedin.com' . $resource . '?' . http_build_query($params);
    // Tell streams to make a (GET, POST, PUT, or DELETE) request
    $context = stream_context_create(
                    array('http' =>
                        array('method' => $method,
                        )
                    )
                );


    // Hocus Pocus
    $response = file_get_contents($url, false, $context);

    // Native PHP object, please
    return json_decode($response);
}

Tuesday 20 August 2013

Recursion in php

<?php

function recursion($int){
    if($int>0){
        echo $int."</br>";
        recursion($int-1);
        echo $int."</br>"; /*values from stack*/
        }
    }
   
recursion(5);

?>

How to preview array in Php ?

Array

<?php

$arr=array(1,2,3,4,5);
echo "<pre>";
print_r($arr);
echo "</pre>";

?>

How to write your first php script ?

What you need ?

1. A server
2. A php file to be put in your www. or htdocs directory..

Phpfile

<?php

echo "My first PHP script!";
 

?>