Posts

Showing posts with the label PHP

Sending HTML mail using PHP

Image
<?php // multiple recipients $emailto  = 'emailto@example.com'; // note: For Multi emailto user comm // subject $subject = 'Email Subject For the mail'; // message $message = ' <html> <head>   <title>Title of th email</title> </head> <body>   <p>Folling is the Details</p>   <table>     <tr>       <th>Some Name 1</th><th>Some Name 2</th>     </tr>     <tr>       <td>Some Value 1</td><td>Some Value 1</td>     </tr>     <tr>       <td>Some Value 1</td><td>Some Value 1</td>     </tr>     <tr>       <td>Some Value 1</td><td>Some Value 1</td>     </tr>   </table> </body> </html> '; // To send HTML mail, the Content-type header must be set $headers  = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Co

Getting success response for Posting XML Data from PHP & curl

I have done the following code for the solution: <?php $url = "http://posttestserver.com/post.php";  // test post server $file="file.xml"; if (file_exists($file)) { // check file existance $headers = array( 'Content-Type: text/xml', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language: en-US,en;q=0.5', 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0', 'Pragma: no-cache', 'Connect: close' ); $xml = file_get_contents($file); $stream_options = array(        'http' => array(        'method'  => 'POST',        'header'  => implode("\r\n", $headers),        'content' => trim($xml)     ), ); echo "Context:".$context  = stream_context_create($stream_options);     //  sending options echo "Response:".$response = file_get_contents($ur

Posting XML Data from PHP & curl

Image
There is a frequent need to post xml data to a url. Below is shown an example which lets you post xml data using CURL. <?php $url = "http://www.some_domain.com"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <rootNode> <innerNode> </innerNode> </rootNode>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header .= $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($c

Check Traffic Sources

Image
Click to large Currently Working on the stuff: if(isset($_GET['token'])) { $token = sanitize($_GET['token']); $sqlcheck = "select `traficsource_source` from `traficsource` where `traficsource_source`='{$token}'"; $result = $dbLink->query($sqlcheck); if($result->num_rows == 0) { $sql1="INSERT INTO `traficsource` (`traficsource_source`, `traficsource_count`, `traficsource_insert`, `traficsource_update`) VALUES ('{$token}', '1', CURRENT_TIMESTAMP, now())"; $result = $dbLink->query($sql1); } else { $sql1="update `traficsource` set `traficsource_count`=(`traficsource_count`+1),`traficsource_update`=now() where `traficsource_source`='{$token}'"; $result = $dbLink->query($sql1); } }

PHP Variable

Image
Click to Enlarge Here I am Describing Basic of Variable. There are many type of variable used in PHP. Following are some: Variable from GET Method  Variable from POST Method  Variable Used in a PHP program itself Variable from SESSION    Variable from COOKIES Variable Type Description GET Method Variable Variable Used as : Array Using Technique : As Following: By referencing in URL i.e. filname.php?variable1=value1&variable2=value2 By Sending by FORM method will be GET i.e. By HTML Input fields like text, password, select etc. Validity/ Scope: Till they reference in URl or sent by Forms Calling as: Called as $_GET['variable1'] and $_GET['variable2'] POST Method Variable Variable Used as : Array Using Technique : As Following: By Sending by FORM method will be POST i.e. By HTML Input fields like text, password, select etc. Validity/ Scope: Till sent by Forms and the File is running Calling

How to connect to Database using PHP

Image
How to connect to Database: Here we will know about the database connectivity on PHP. Firstly we have to check database credential of the server, Usually They are as following: For Local Server (i.e. XAMPP/ WAMPP etc.) Server: localhost Username: root Password:   (blank) For Server  (i.e. cpanel, window etc) Server: localhost  or domain name of the website Username: can be created by Hosting panel using Database wizard (Cpanel) or Option proided on the same Password:  same as above We have to create a database to connect with a particular database for a particular  website or Program. Now we will define all on a variable: <?php $databaseserver = "localhost";   // can be changed as required $databaseuser =  " dbadmin ";   // as exapmle I have taken it dbadmin $databasepassword = "W3help@123";  // as exapmle,  use password as strong, use Capital, small, Number and special Character. Probability of such password guessing is les

Visitor Count for Website in PHP

Hello, Here I am writing a small program in PHP for  checking how much user have visited our website using COOKIES, MYSQL and IP address of the user. First we have to create cookies for the new user. This the code we will use for that: (I have make a cookies for 30 days) setcookie('ipaddress',$_SERVER['REMOTE_ADDR'],time()+(60*60*24*30)); Secondly we have to create a table on database to store the number of Visitors. I have created a table i.e. usercounter with following attribute:  (Initially Insert value with o and 1 on useripid ) useripid   (INT type - AUTO-INCREMENT) lastaddress   (VARCHAR    -   Last visitor IP) userqua   (INT)   (Counter for visitor)  (Initially 0) lastmodified   (TIMESTAMP)   (Last modified time for database) Now we have to check whether user are coming on website for first time or He has already visited. if(isset($_COOKIE['ipaddress'])) { // check is the same ip if($_COOKIE['ipaddress']==$_SERVER['REMO