Tuesday, March 27, 2012

Get Url From Browser in Php

Getting the URL  from the parent window when you use a popup. This small Example code might help you to get the url from the parent window this can be used normal windows also

 if(isset($_SERVER['HTTP_REFERER']))
{
   
    $strPrevScheme = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_SCHEME);
 
    $strPrevHost = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
 
    $strPrevPath = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH);
 
    $strPrevURL = urlencode($strPrevScheme.'://'.$strPrevHost.$strPrevPath);
   
   
}

the parse_url(url) gives the following array 

Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)
 

 
reference - http://in2.php.net/manual/en/function.parse-url.php 

Monday, March 26, 2012

Finding the Count of all Charecters entered


<?php
/******************************************************************************
 * Filename: totalnumberofalphabets.php
 * Description: The file is used to count the number of occurences of each charecter
 * Author: G Jayendra Kartheek
 * Date Created: 26 Mar 2012
 * Copyright © 2012 All rights reserved
 ******************************************************************************/

//after user submits the values
if (isset($_POST['butSubmit']) && '' != $_POST['butSubmit']) {

    //taking the charecter into the array
    $strValue = str_split($_POST['txtInput']);
    //copying the string array
    $strDuplicate = $strValue;
   
    $iIntI = 0;
    //based on the string length travesing the array
    while ($iIntI < strlen($_POST['txtInput'])) {
        //initializing the count and j for every iteration
        $iCount = 0;
        $iIntIIntJ = 0;
        //comparing each and every element  and finding the count of each element
        while ($iIntIIntJ < strlen($_POST['txtInput'])) {
            if ($strDuplicate[$iIntI] == $strValue[$iIntIIntJ]) {

                $iCount++;
            }
            $iIntIIntJ++;
        }
        //printing the count
        echo '<br>Number of times "' . $strDuplicate[$iIntI] . '" repeated is : ' . $iCount;
        $iIntI++;
    }
}
?>
<form name="" method ="POST">
    <input type='text' name = 'txtInput'/><input type = 'submit' name= 'butSubmit' value ="OK"/>
</FORM>

Thursday, March 22, 2012

Closing the PopUp and redirecting Parent Window

I have tried for few hours to solve this problem Here is the simple example which helps you to solve the Problem

Problem:
 Create a PopUp window on submission of a value in PopUp the PopUp Closes and the Parent Windows redirects to Some other Page 

Solution:
Here is the simple way to solve it

Create 2 php pages

1. popup.php
Copy this Code

<html>
    <head>    
    </head>
    <body>
        <a href="#" onclick="window.open('popupcode.php','Login','height=500,width=420,scrollbars=yes');return false;">PopUp</a>
    </body>
    </html>




Tuesday, March 20, 2012

Count Number of tables in a Schema

This is a very Simple query to find the number of tables present in a purticular schema of the database


select information_schema as your default schema and use the following query to find the count of number of tables in a particular schema


SELECT count(*) FROM 'TABLES' WHERE TABLE_SCHEMA = 'YOUR_SCHEMA_NAME*'



*YOUR_SCHEMA_NAME = NAME OF THE SCHEMA TO WHICH YOU ARE FINDING THE COUNT







Switch Off Foreign Key Constraint

I used to use this code regularly but when i found it for the first time it took me to read many pages to read after getting the code i thought this would be useful for all people like me who want to Switch off the Foreign key Constraint in their tables

This is helpful when you are actually want to create tables irrespective of the Foreign key constraint 

To Turn Off - SET FOREIGN_KEY_CHECKS = 0;

To Turn On - SET FOREIGN_KEY_CHECKS = 1;


OAuth 2.0

Now its time to Switch on the easier and secured version of OAuth Protocol OAuth 2.0 so here is the presentation i have made which makes u people easy to understand the Protocol and important points to have talk to the server 


Presentation  - Download 




The presentation is based on the Oauth 2.0 written by the developers of Microsoft and Facebook on January 2012







Tuesday, March 13, 2012

Difference between Echo and Print in Php

We have Echo we have print in php which we use to display the output to the user
Both Echo and Print does the same work - Displaying the output on the screen
But there are couple of differences between them
Echo
  1. Output one or more strings
  2. Allows More parameters works only with the short open tags
  3. It is not a function
  4. It takes less memory

Print
  1. Output only one string
  2. It allows only one parameter
  3. Its not a real function but its a language construct
  4. It take a little more memory than echo