Post data to a specific port using PHP/Curl.

Post data to a specific port using PHP/Curl.

In this article,I will show how to Post data to a specific port using PHP/Curl Method. PHP-curl library can be used to communicate with a specific port under Linux and windows platform.

Example: Send data to Port in PHP.

  <?php
ini_set("display_errors",1);
error_reporting(E_ERROR);

$msg="&command=1";
$url = "http://127.0.0.1:1234";

$curl = curl_init();
curl_setopt($curl,  CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $msg);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);

if($response!="")
{
$fp = fopen("test.txt","w");
fwrite( $fp, $response);
fclose($fp);
}

curl_close($curl);
?>





Bookmark and Share

Apache Interview Questions and Answers - Apache Web Server

Apache Interview Questions and Answers - Apache Web Server


In this section, I have selected Basic and Important Apache interview questions and answers for all levels of candidates(Fresher level, experienced level).Last few months I have been working to select best question and answer set for Apache  interview questions.

Apache Interview Questions and Answers:
------------------------------------------------------------------------------------------------------------

How do you set up a virtual host in Apache?

Ans: <VirtualHost www.test.com>
    ServerAdmin admin@test.com
    DocumentRoot /home/Public_html/site
    ServerName www.test.com
    ErrorLog /home/apache/logs/error/site/error_log
    TransferLog /home/apache/logs/access/site/access_log
</VirtualHost>
------------------------------------------------------------------------------------------------------------

htpasswd :
Ans: It creates a new user and asks to specify a password for that user.
------------------------------------------------------------------------------------------------------------

What's the command to stop Apache?
Ans:
apachectl -k stop
/etc/init.d/apache2 stop (Linux)
------------------------------------------------------------------------------------------------------------

What's the command to Restart Apache?
Ans:
apachectl -k restart
/etc/init.d/apache2 restart
------------------------------------------------------------------------------------------------------------

What's the location of log files for Apache server ?
Ans:  /var/log/httpd
------------------------------------------------------------------------------------------------------------

What's the Comamnd to check the version of Apache server ?
Ans: rpm -qa |grep httpd
------------------------------------------------------------------------------------------------------------

Apache server works on which ports ?
Ans: http – port 80
     https – port 443
------------------------------------------------------------------------------------------------------------

How t to enable PHP scripts on your server?
Ans: If you have mod_php installed, use AddHandler.
AddHandler application/x-httpd-php .phtml .php
------------------------------------------------------------------------------------------------------------

If you specify both deny from all and allow from all, what will be the default action of Apache?
Ans: Deny always takes precedence over allow.
------------------------------------------------------------------------------------------------------------

How do you change the default web root?
Ans: Change the DocumentRoot in httpd.conf file.
------------------------------------------------------------------------------------------------------------

How to enable htaccess on Apache?
Ans:
Open httpd.conf and remove the comment on line from

;LoadModule rewrite_module modules/mod_rewrite.so

Find the following
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

and change it to
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
------------------------------------------------------------------------------------------------------------

Does Apache act as Proxy server?
Ans: Yes,using mod_proxy module.
------------------------------------------------------------------------------------------------------------


Bookmark and Share

Print a web page using PHP/JavaScript Code

Print a web page using PHP/JavaScript Code

In this article I will show how to Print a HTML Web Page using PHP/JavaScript.I have Written simple script to print Visitor card in PHP.On web page, there is a print option. When the user click on `print` Button it will send a print command to the printer.
We are using Javascript window.print(); function to print HTML portion of a Web Page.

Javascript window.print():
 The window.print() method prints the contents of the current page.This method is supported in all major browsers.

Example: How to Print a Web Page Using JavaScript and PHP.

<!DOCTYPE html>
<HTML lang="en"><HEAD>
<TITLE>Print Visitor card using PHP/JavaScript </TITLE>
<META content=IE=7 http-equiv=X-UA-Compatible>
<META content="text/html; charset=Windows-1252" http-equiv=Content-Type>
<STYLE>
#outer
{
  border-collapse:collapse;
  border: 0px solid black;
  height:250px;width:420px;
 }
.cover{
background:#EEEEEE;
padding: 10px;
text-align:left;
margin:10px;
width:400px;
height:200px;
font-size: 1.0em;
top:10%; left:10%;
/*--CSS3 Box Shadows--*/
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
/*--CSS3 Rounded Corners--*/
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
border-radius: 30px;
}
#inner
{
  border-collapse:collapse;
  border: 0px solid black;
  height:100%;width:100%;
  background:#EEEEEE;

}
#hgt_abv
{ height:18%;}
#hgt_abv_back
{   float:inherit;
height:18px;
width:400px;
background:#000000;
}
#hgt_belo
{ height:3%;background:#FF6600;}
.docimg
{
float:inherit;
hight:119px;
width:90px;
}
.logo
{
float:left;
width:100px;
}
.address
{
    padding:2px;
text-align:left;
margin:2px;
hight:100px;
width:130px;
font-size: 1.1em;
}
</STYLE>
<META name=GENERATOR content="MSHTML 9.00.8112.16446"></HEAD>
<BODY class="ExtravaganzaAqua page-view2" >
<CENTER><SPAN></SPAN>

<TABLE id=outer>
<TR>
<TD><DIV class=cover>
<TABLE id=inner border=0>
<TR>
<TD align=center colspan="2">
<DIV id=hgt_abv_back><FONT color=#ffffff size=3><B>VISITOR     PASS</B></FONT></DIV>
</TD>
</TR>
<TR>
<TD valign="top" align=left><br /><FONT size=2><B>Name: </B><B>Computer Geek</B><br /><br /><br />
<B>Designation: </B><B>Software Engg.</B><br /><br /><br />
<B>Date: </B><B>24th Nov 2012</B><br />
</FONT>
</TD>
<TD valign="top" align=right>
<img width="90" hight="119px" src="user.jpg" alt="bg">
</TD>
</TR>
<TR id=hgt_belo>
<TD colSpan=2></TD>
</TR>
</TABLE>
</DIV>
</TD>
</TR>
</TABLE>
</CENTER>
<center>
<table id=outer>
<tr>
<td align="right" valign="top">
<button type="button" onclick="window.print();" >Print</button>
</td>
</tr>
</table>
</center>
</BODY>
</HTML>


I hope this example will help you to Print a Web Page Using JavaScript and PHP.


Bookmark and Share

C Interview Questions and Answers For Freshers/ Experienced

C Interview Questions and Answers For Freshers / Experienced - Important Quiz 

In this section, I have selected Basic and Important C interview questions and answers for all levels of candidates(Fresher level, advanced level,experienced level).
Last few months I have been working to select best question and answer set for C interview questions.

Here is some Important C Interview Questions and Answers for freshers and experienced:

1.Can we have a pointer to a pointer in C?

Answer: Yes

char *a;      -   Pointer to a character

char **a;      -    Pointer to a pointer

2.How to convert strings in c to corresponding Integer?

Answer:
atoi() function convert a string into corresponding integer value.use stdlib.h header file.

3. C Data types?
Answer :Int, char, float, void etc. are predefined basic primitive data types.Structures and Unions are user defined data types.

4.Find the output of the following program? 
#include 
main() 

int i=10; 
printf("%d",++i); 
printf("%d",i++); 
printf("%d",(i++*i++)) 


5.Octal literal in C?
#include
main()
{
int i=020;
printf("i is %d",i);
}
Output:16

Answer :
In c and c ++ language 0 (zero) is the octel literal so it will print its Octel representation of 16.

6.Whats is difference between file descriptor and file pointer?

7.Two forms of #include directive?
Answer :
1.#include”filename”
2.#include

8.Find the output of the following program? 
#include 
main()

    int str=0; 
    if(str==0) 
        printf("True"); 
printf("False"); 
}
Answer :
True
False

9.Find the output of the following program? 
#include 
main()

    int x=0; 
    if(x==0) 
        printf("True"); 
else
printf("False"); 
}

Answer :
True

10.What will be the Output of the following program? 
#include
main()

    int i=50, j=100; 
    i = j++; 
    j = ++j; 
    printf("%d %dn",i,j);
}

Answer :
51, 101

11.What will be the Output of the following program? 

#include
main()
{
int i = 10;
printf("%d", main||i);
}

Answer :
1

12. Write a Program to convert decimal to binary number?
Answer :
#include
main()
{
int x,y,n,arr[50];
clrscr();
printf("Enter the decimal number");
scanf("%d",n);
for(x=0;x
{
arr[x]=n%2;
n=n/2;
}
for(y=n;y>0;y--)
{
printf("%d",arr[y]);
}
getch();
}

Top Important C FAQs and Interview Questions

  1. What is the difference between strings and character arrays?
  2. Differences between pass by reference and pass by value?
  3. What does static variable mean?
  4. What is the use of semicolon at the end of every statement?
  5. What is a null pointer?
  6. What is a pointer?
  7. When would you use a pointer to a function?
  8. What are the uses of a pointer?
  9. In header files whether functions are declared or defined?
  10. What are the differences between malloc () and calloc ()?
  11. What is the heap?
  12. What is the stack?
  13. Difference between const char* p and char const* p?
  14. What is a structure?
  15. What is a union?
  16. What is Operator overloading ?
  17. What is a void pointer?
  18. What is hashing?
  19. What are the different storage classes in C?
  20. What are the differences between structures and union?
  21. What is the difference between calloc() and malloc()?
  22. What are the differences between structures and arrays?
  23. What is the difference between printf() and sprintf()?
  24. What is static memory allocation and dynamic memory allocation?
  25. Define recursion in C?
  26. What is the use of typedef?
  27. How are pointer variables initialized?
  28. What are the advantages of auto variables?


Bookmark and Share

C Program to find smallest number with Output in a given array of elements.


C Program to find smallest number with Output  in a given array of elements.

In this article ,I have written simple c program to find smallest number in a given array of elements.

Interview Question : Write a program to find the smallest and largest element in a given array in c?

Example:

/***
Program to find smallest Number
***/

#include<stdio.h>
#include<conio.h>
main()
{
    int arr[50],n,j,s;
    clrscr();
    printf("Enter the size of array:");
    scanf("%d",&n);
    printf("Enter %d integers:",n);
    for(j=0;j
    scanf("%d",&arr[i]);
    s==arr[0];
    for(j=0;j
    {
        if(arr[i]
        s=arr[i];
       
    }
    printf("Smallest number is  %d",s);
    getch();
}

Output:

Enter the size of array:3
34
35
60
Smallest number is: 34


Bookmark and Share