Saturday 28 April 2012

Include a page from url in php


                                   This article is to describe how to include a page from other web site to our php page.
                                php include url is not so simple as include a file in your site. We can edit web pages  by including it to our php page.
     

                                   php include external url  is not use include()  or  require() methods of  php  , which are used for local inclusion of  pages in our site.


    If we want to use that     we may use allow_url_include php for that.
     Here I am using  file_get_contents()   for this purpose.
   
     Code
   
<?php

  $cnt=file_get_contents('http://www.gmail.com');
  echo $cnt;
  echo "<div style=\" position:absolute;left:150px;top:50px \">
  <h1 style=\"color:red\">Successfully included By Sukesh B R
  </h1></div>";

?>


                     Here I am including the Gmail home page.  So give the URL ' http://www.gmail.com ' as
 parameter to file_get_contents() .         The return value from this is stored to the variable
 $cnt.     Then print this using echo statement.


 
                     Hence the Gmail page is displayed just like my local    html page.  Then I include a   <div>    in which a message    'Successfully included By Sukesh B R'       is displayed.I have use little css to display it in the top of gmail page.


Here is a sample screenshot of this page :-




                 



You can add javascript blocks to this page and access the elements of Gmail home page  and make changes in it with your like.You can add any other webpages just like this.


You can also read:- Download image file using PHP

                   Thanks for reading this article.       Please  just tick a response in the Reactions check boxes provided
 under this .

Monday 23 April 2012

Extend maximum execution time of php script


Hi friends ,
today my discussion is about  extend maximum execution time of php script/page .
OR  solution for Fatal Error:Maximum execution time limit reached  when you run a php page .
OR change the maximum execution time of php script.OR increase the maximum execution time of
php script
.
        We can change the maximum execution time by call a function set_time_limit().
       
       
Syntax

   void set_time_limit ( int $seconds );
    //set_time_limit(300);



                The parameter send to this specifies the maximum execution time in seconds.In the above code the maximum execution time is set to 300 seconds , that is 5 minutes.

This can also achieve by using the function ini_set() , like this ,

   ini_set('max_execution_time', 300);  


                Here also 300 is the maximum execution time in seconds.

Hope that this post is helpful to you.

Thanks by Sukesh B R

You can also read :-
Delete non empty directory in php

Friday 20 April 2012

Download image file using PHP


Hi friends,
 today my discussion is about how to download an image from an URL using php.OR download picture from the given URL.OR save image file using php.

 Here have two functions used for this:-
     file_get_contents() and file_put_contents()
   
    Code
<?php
set_time_limit(300) ;
$lnk='http://1.bp.blogspot.com/-SZgenQisfQc/TVPnClZOn5I/AAAAAAAABO8/zLFsX4UoFzg/s1600/The-best-top-desktop-dolphin-wallpapers-hd-dolphins-wallpaper-3.jpg';
file_put_contents('image.jpg',
    file_get_contents($lnk));   
?>

   




Code Description
 set_time_limit(300) ;   This statement is used to set the maximum execution time for the php script.It's default value  is 60 seconds.  Set this to 300 seconds allow the time to download the image.
 $lnk holds the URL of a wallpaper image to be download.

     file_get_contents() is used for get the contents from URL. Where file_put_contents() is used
 to write these contents to a file.
           

                 The lnk is given to the parameter to   file_get_contents().  The return data from this and
the name of file to be saved is given to file_put_contents().  Here all these are written in single step.
When you run this script the image will downloaded  to the location where your php page is saved
with the name 'image.jpg'.  To change the download location give it to file_put_contents() parameter
like this file_put_contents( 'imgfolder/img/image.jpg' , '...'  );

Also read this :- Include a page from url in php

Hope that this post is helpful to you.
Thanks By Sukesh B R

Tuesday 17 April 2012

Add tool tip text to HTML elements



Hi friends ,
Have you Think about giving tool tip text to HTML elements?
Today I am going to discuss add tool tip text to HTML elements.OR add a short descriptions to
links or buttons in HTML
.OR the use of title attribute in HTML.

      Tool tip text is defined as a short description given to a link or button which gives information
about what the link is for.
      title attribute is used to create a tool tip text(Not the <title> tag). Just like other attributes type like this
tiltle="description".

1. For add a tool tip to a link

<a title="Link to Google" href="www.google.com">This is a link</a>


The resultant screenshot is given belove :-







2. For add a tool tip to a Button


<input type="button" title="This is a button"value="Button">


The resultant screenshot is given belove :-

 


3. For add a tooltip to a Textbox :-


<input type="text" title="This is a Textbox">


The resultant screenshot is given belove :-



The title attribute is not valid in: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.
Hope that this post is helpful to you.
  By Sukesh B R

Friday 13 April 2012

Pass parameter to another page in PHP


I am discussing How to pass parameters as type GET to another page. OR Pass parameters as GET without using a form.OR Pass parameters through URL.

When we are using a form of method GET the values of text boxes enclosed in the form are
send to the action page through the URL.We can also send values through URL without a form.


If we want to pass a variable to another page when click a link
<a href="target.php?n1=5">Click Here</a>


If we want to pass more than 1 values seperate them with ' & '.
<a href="target.php"?n1=5&n2=10&name=sbr>Click Here</a>


In target.php the values can be retrieved just like form values send as GET method.
That is
$n1=$_GET["n1"];
$n2=$_GET["n2"];
$name=$_GET["name"];






When we want to send values of php variables , these code may be helpful

1.Pass a single value to another page

t1.php
<?php
$n1=5;
?>


<a href="target.php?n1=<?php echo $n1 ;?>">Click Here</a>

target.php
<?php
echo $_GET["n1"];
?>


2.Pass more than one value to another page

t1.php

<?php
$n1=5;
$n2=7;
?>

<a href="target.php?n1=<?php echo $n1 ;?>&n2=<?php echo $n2;?>">Click Here</a>

target.php

<?php
echo $_GET["n1"];
echo $_GET["n2"];
?>

You can see these two examples of using this  method here :-


Change font size of text in HTML page dynamically using  php



Hope that this post is helpful to you.
By Sukesh B R

Thursday 5 April 2012

ACCESS $_GET , $_POST , $_SESSION using javascript

Hi friends I am going to discuss Access $_GET or $_POST or $_SESSION using javascript.
In other words access parameters send by form as POST or GET method or
Read the session variables in the server using javascript.



    1.Access $_GET values using javascript

Code
<html>


<head>


  <script type="text/javascript">
            var $_GET = <?php echo json_encode($_GET); ?>;
           
            alert($_GET["n1"]); 
  </script>


</head>




         <body>
        <form method="GET">
        <input type="text" name="n1">
        <input type="submit">
        </form>
        </body>




</html>

Code Description

json_encode() is the core function using here.In the javascript section a variable named $_GET
is declared.This variable is assigned with the $_GET array of php page.This is done by this statement :
var $_GET = <?php echo json_encode($_GET); ?>;
Dont forget the semicolon at the end.
All the parameters passed as GET to the page will stored in the variable.These values can be retrived
by their name.That is the name of the textbox in the html page.Here my textbox's name is 'n1'.So I use
$_GET["n1"] to access the value of n1.
save it as a php file(.php extension) and run.



   2.Access $_POST values using javascript

Code
<html>


<head>


  <script type="text/javascript">
            var $_POST = <?php echo json_encode($_POST); ?>;
           
            alert($_POST["n1"]); 
  </script>


</head>




         <body>
        <form method="POST">
        <input type="text" name="n1">
        <input type="submit">
        </form>
        </body>




</html>


Code Description

json_encode()  is the core function using here.In the javascript section a variable named $_POST
is declared.This variable is assigned with the $_POST array of php page.This is done by this statement :
var $_POST = <?php echo json_encode($_POST); ?>;
Dont forget the semicolon at the end.
All the parameters passed as POST to the page will stored in the variable.These values can be retrived
by their name.That is the name of the textbox in the html page.Here my textbox's name is 'n1'.So I use
$_POST["n1"] to access the value of n1.

save it as a php file(.php extension) and run.

 
   3.Access $_SESSION values using javascript


Code
<?php session_start(); ?>
<html>


<head>


  <script type="text/javascript">
            var $_SESSION = <?php echo json_encode($_SESSION); ?>;
           
            alert($_SESSION["ns"]); 
  </script>


</head>




         <body>
<?php
$_SESSION["ns"]="SESSION_VALUE";
?>
        <form method="POST">
        <input type="text" name="n1">
        <input type="submit">
        </form>
        </body>




</html>

Code Description

json_encode() is the core function using here.
First of all in a php section we call the function session_start().This is for accessing SESSION variable in php.
In the javascript section a variable named $_SESSION  is declared.This variable is assigned with the $_SESSION array of php page.
This is done by this statement :
var $_SESSION = <?php echo json_encode($_SESSION); ?>;
Dont forget the semicolon at the end.
All the SECTION variables  will be stored in the variable $_SESSION.These values can be retrived
by their name.Here my section variable's  name is 'ns'.So I use
$_POST["ns"] to access the value of 'ns'.
save it as a php file(.php extension) and run.

You can also read :-

Search This Blog