function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
Its is used to disabled the charactor key pressing on javascript.
java script function
<--------------------------
function isnumky(evt)
{
var char1 = (evt.which) ? evt.which : event.keycode
if (char1 > 31 && (char1 < 48 || char1 > 57))
return false;
return true;
}
---------------------------------------->
html form
<input name="textfield" type="text" onkeypress="return isnumky(evnt)" size="50" />
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
if(re.test(birthday.value ))
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
this prgm used to fetch the contents from other servers .... wil set the sleeping time and and will see the time taken and how to fetch ,,, by using curl with php mutitreading
<style type="text/css">
<!--
.style2 {color: #FF0000; font-style:oblique; font-size:24px;}
-->
</style>
<?php
function addHandle(&$curlHandle,$url)
{
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($curlHandle,$cURL);
return $cURL;
}
//execute the handle until the flag passed to function is greater then 0
function ExecHandle(&$curlHandle)
{
$flag=null;
do {
curl_multi_exec($curlHandle,$flag);//fetch pages in parallel
} while ($flag > 0);
}
for ($i = 1;$i <= 4; $i++)
$curl[$i] = addHandle($curlHandle,$list[$i]);
ExecHandle($curlHandle);
for ($i = 1;$i <= 4; $i++)
{
// set the sleeping time on 2 seconds
usleep(2000000);
{
// get the content from other servers
$text[$i] = curl_multi_getcontent ($curl[$i]);
echo $text[$i];
}
echo "<span class='style2'>$i time out".date("h:i:s")."</span>";
}
for ($i = 1;$i <= 4; $i++)//remove the handles
curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);
this program used to hit the target ftp/http/https........hit at multiple times... will getta response from multiple times.....i hope this is example useful for u....
example:-
<?php
error_reporting(0);
// create the multi curl handle
$mh = curl_multi_init();
$handles = array();
for($i=0;$i<5;$i++)
{
// create a new single curl handle
$ch = curl_init();
// setting several options like url, timeout, returntransfer
// simulate multithreading by calling the wait.php script and sleeping for $rand seconds
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/IPtest/Timeout.asmx/HelloWorld");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch , CURLOPT_POSTFIELDS,"test='($i+1)'&value='ram'");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// add this handle to the multi handle
curl_multi_add_handle($mh,$ch);
// put the handles in an array to loop this later on
$handles[] = $ch;
}
// execute the multi handle
$running=null;
do
{
curl_multi_exec($mh,$running);
// added a usleep for 0.25 seconds to reduce load
usleep (250000);
} while ($running > 0);
// get the content of the urls (if there is any)
for($i=0;$i<count($handles);$i++)
{
// get the content of the handle
$output=curl_multi_getcontent($handles[$i]);
// remove the handle from the multi handle
curl_multi_remove_handle($mh,$handles[$i]);
//echo the output to the screen multiple times echo $output."<br>";
}
// echo the output to the screen
// echo $output;
// close the multi curl handle to free system resources
curl_multi_close($mh);
<?php
if(isset($_REQUEST['submit']))
{
//$toadd = $_REQUEST['to'];
//define the receiver of the email
$to = $_REQUEST['to'];
$array = explode(",", $to);
//define the subject of the email
$subject = $_REQUEST['subject'];
//define the message to be sent. Each line should be separated with \n
$message = $_REQUEST['textarea'];
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: it.siddarth@gmail.com\r\nReply-To: it.siddarth@gmail.com";
//send the email
if($to!="")
{
foreach ($array as $k => $v)
{
// echo $v."</br>";
$mail_sent = @mail( $v, $subject, $message, $headers );
}
echo "You have referred the following your friends email ids $to ";
}
else
{
echo "check ur refferal email_ids";
}
}
?>
<form id="form_id" method="post" action="mutiplemails.php" >
<p>Invite Friends Here :
<input type="text" id="emailq" name="to" />
<input type="submit" name="submit" value="Invite" />
subject:
<input name="subject" type="text" />
content:
<textarea name="textarea" rows="5" > </textarea></p>
</form>
<php
if(isset($_REQUEST['submit']))
{
//$toadd = $_REQUEST['to'];
//define the receiver of the email
$to = $_REQUEST['to'];
$array = explode(",", $to);
foreach ($array as $k => $v)
{
$ids= explode(",", $v);
//echo " ". $ids[0]; if($ids!="") {
if (!preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", $ids[0]))
{
echo "<font color='red'>something is Invalid email id's </font>";
}
else{
echo "<font color='green'> Valid Email id's </font>"; } }
}
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: k.v.n.krishnakumar@gmail.com\r\nReply-To: k.v.n.krishnakumar@gmail.com";
//send the email
$mail_sent = @mail( $ids[0], $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "You have referred the following your friend email id's:' $ids[0]' " : "Referral sending failed to:'$to' this id";
}
{_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function()
Cookies are small bits of information that can be stored on a client computer. Once a cookie is created, it will expire after a specified time period. All the information stored in a cookie exist until it expires or deleted by the user.
Why we need Cookies:-
Now-a-days most of the websites use cookies to store small amounts of information. Websites can read the values from the cookies and use the information as desired. The browser is capable of keeping track of the websites and their corresponding cookies and is capable of reading the information from relevant cookies. Some common use of cookies include:
User's aesthetic preference for a specific site.
User keys to link them with their personal data - as used by many Shopping Cart Applications.
Allowing a user to remain 'logged on' until he explicitly logs out or the browser window is closed.
create a cookie
Cookies can be set using the 'setcookie' function in PHP. This function takes three arguments - name of the variable, value of the variable and the expiry time period. The syntax to set a cookie using PHP is as given below:
Syntax:setcookie("variable","value","time");
variable - name of the cookie variable
value - value of the cookie variable
time - expiry time
Example: setcookie("Test",$kris,time()+3600);
Test - cookie variable name
$kris - value of the variable 'Test'
time()+3600 - denotes that the cookie will expire after an one hour
reset/destroy a cookie
There are several ways to destroy cookies. Cookies can be deleted either by the client or by the server. Clients can easily delete the cookies by locating the Cookies folder on their system and deleting them. The Server can delete the cookies in two ways:
Reset a cookie by specifying expiry time
Reset a cookie by specifying its name only
Reset a cookie using name:
Syntax:setcookie('cookiename');
Example:setcookie("test")
Reset/Destroy a cookie using expiry time:
The cookie can be set with an expiry time while creating the cookie using the 'setcookie' function. This is also a method used to destroy cookies.