Simple way yo disable right click:
<body oncontextmenu="return false;">
Using script:
<script>
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
</script>
From: http://www.reconn.us/content/view/36/45/
Now...
Can i disable right click only on images?
Yes, by using getElementsByTagName i can set no right click on images only
<script>
function noRtClk(){
return false;
}
//document.oncontextmenu = noRtClk;
var e=document.getElementsByTagName("img");
for(var i=0;i<e.length;i++)
{
e[i].oncontextmenu = noRtClk;
}
</script>
Reference: http://www.aglasshalffull.org/css-resources/Using-getElementsByTagName-and-getElementsByName.htm
Thats it.
Saturday, January 3, 2009
Thursday, December 11, 2008
meta refresh problem in IE7
<meta equiv="Refresh" content="3;url=http://mysite.com">
this meta tag will redirect to the specified url in 3 seconds.
but it won't work in Internet Explorer 7.
BUT...
we can use a script...
function Refresher(t) {
if(t) refresh = setTimeout("document.location='http://www.mysite.com';",
t*1000);
}
Then call it inside body tag..
<BODY onLoad="Refresher(20)">Cheers!
Wednesday, December 10, 2008
php explode and implode
Use of Explode and implode functions
Explode - splits a string by a string
eg:
$a = explode("/","23/02/2008");
then
$a[0] = "23"
$a[1] = "02"
$a[2] = "2008"
Implode - joins array elements into string with a string
$b = implode("-",$a);
then
$b = "23-02-2008"
http://in.php.net/manual/en/function.explode.php
http://in.php.net/manual/en/function.implode.php
Explode - splits a string by a string
eg:
$a = explode("/","23/02/2008");
then
$a[0] = "23"
$a[1] = "02"
$a[2] = "2008"
Implode - joins array elements into string with a string
$b = implode("-",$a);
then
$b = "23-02-2008"
http://in.php.net/manual/en/function.explode.php
http://in.php.net/manual/en/function.implode.php
Getting Last generated auto increment value in mysql
Some tables have auto increment field.
after executing a insert command in mysql, sometimes we may want to know the last added value.... for that we can use
mysql_insert_id()
function
eg:
mysql_query($sql3); //executing some query
$last_num = mysql_insert_id(); //last added value
Cheers!
after executing a insert command in mysql, sometimes we may want to know the last added value.... for that we can use
mysql_insert_id()
function
eg:
mysql_query($sql3); //executing some query
$last_num = mysql_insert_id(); //last added value
Cheers!
Wednesday, November 5, 2008
PHP - Mysql, database access
How to get data from mysql database using php?
student Table (consider this table already in database - school and having the following data)
---------------
s_no | name
---------------
1 | Regin
2 | Beschi
3 | Siva
4 | Karthik
----------------
then the code to display data:
$con = mysql_connect("localhost","root",""); //local
//for server - mysql_connect("hostname/ip","username","password")
if($con)
mysql_select_db("school",$con); //database name
$sql = "select * from student";
$rsd = mysql_query($sql);
$total_students = mysql_num_rows($rsd); //total number of records in student table
while($rs = mysql_fetch_array($rsd))
{
echo $rs['s_no']." - ".$rs['name'];
echo "
";
}
mysql_close();
?>
Output:
1 - Regin
2 - Beschi
3 - Siva
4 - Karthik
This is a simple way to connect with a database.
Cheers!
student Table (consider this table already in database - school and having the following data)
---------------
s_no | name
---------------
1 | Regin
2 | Beschi
3 | Siva
4 | Karthik
----------------
then the code to display data:
$con = mysql_connect("localhost","root",""); //local
//for server - mysql_connect("hostname/ip","username","password")
if($con)
mysql_select_db("school",$con); //database name
$sql = "select * from student";
$rsd = mysql_query($sql);
$total_students = mysql_num_rows($rsd); //total number of records in student table
while($rs = mysql_fetch_array($rsd))
{
echo $rs['s_no']." - ".$rs['name'];
echo "
";
}
mysql_close();
?>
Output:
1 - Regin
2 - Beschi
3 - Siva
4 - Karthik
This is a simple way to connect with a database.
Cheers!
Friday, October 10, 2008
how to change month number to month name?
how to change month no to month name?
link 02 to february or Feb...
function month_name($month_no)
{
$timestmp = mktime(0,0,0,$month_no,1,2008);
return date("M",$timestmp);
}
echo month_name(10); //will return October
?>
Cheers!
link 02 to february or Feb...
function month_name($month_no)
{
$timestmp = mktime(0,0,0,$month_no,1,2008);
return date("M",$timestmp);
}
echo month_name(10); //will return October
?>
Cheers!
Thursday, September 25, 2008
Form validation with javascript
Here is an example for form validation with javascript
<html>
<head>
<title>From Validation</title>
<script language="javascript">
function chkForm(form)
{
if(form.cname.value == ""){ alert("Enter Name"); form.cname.focus(); return false; }
if(form.age.value == "0"){ alert("Select Age Level"); return false; }
}
</script>
</head>
<body>
<div align="center">
<form name="test" action="some_page.php" method="post" onsubmit="return chkForm(this);">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="table1">
<tr>
<td width="139">Name</td>
<td><input type="text" name="cname" size="20"></td>
</tr>
<tr>
<td width="139">Age</td>
<td><select size="1" name="age">
<option selected value="0">Select</option>
<option value="below 18">below 18</option>
<option value="18+">18+</option>
</select></td>
</tr>
<tr>
<td width="139"> </td>
<td><input type="submit" value="Submit" name="B1"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Older posts
Radio button validation:
http://phpbeginners.blogspot.com/2008/06/radio-button-validation-in-javascript.html
checkbox validation:
http://phpbeginners.blogspot.com/2008/05/checkbox-validation-in-javascirpt.html
<html>
<head>
<title>From Validation</title>
<script language="javascript">
function chkForm(form)
{
if(form.cname.value == ""){ alert("Enter Name"); form.cname.focus(); return false; }
if(form.age.value == "0"){ alert("Select Age Level"); return false; }
}
</script>
</head>
<body>
<div align="center">
<form name="test" action="some_page.php" method="post" onsubmit="return chkForm(this);">
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="table1">
<tr>
<td width="139">Name</td>
<td><input type="text" name="cname" size="20"></td>
</tr>
<tr>
<td width="139">Age</td>
<td><select size="1" name="age">
<option selected value="0">Select</option>
<option value="below 18">below 18</option>
<option value="18+">18+</option>
</select></td>
</tr>
<tr>
<td width="139"> </td>
<td><input type="submit" value="Submit" name="B1"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Older posts
Radio button validation:
http://phpbeginners.blogspot.com/2008/06/radio-button-validation-in-javascript.html
checkbox validation:
http://phpbeginners.blogspot.com/2008/05/checkbox-validation-in-javascirpt.html
Labels:
checkbox,
html,
javascript,
radio button,
validation
how to change the alert box title?
Want to know how to change the alert box title in javascript...
the answer is: we cant change the title of js alert box.
however, we can use popup boxes, that look like alert boxes with custom title.... but there is a chance - some browsers will block that.
Or we can use vbscript msgBox, but cant get the result in FF.
Or we can use custom designs like this:
http://www.acejs.com/scriptsfolder/121015/121015.html
BUT it is not working like exactly as a alert box. (following codes will get executed though we dont click the ok button)
My opinion: Its better not to use any other custom alert boxes.
the answer is: we cant change the title of js alert box.
however, we can use popup boxes, that look like alert boxes with custom title.... but there is a chance - some browsers will block that.
Or we can use vbscript msgBox, but cant get the result in FF.
Or we can use custom designs like this:
http://www.acejs.com/scriptsfolder/121015/121015.html
BUT it is not working like exactly as a alert box. (following codes will get executed though we dont click the ok button)
My opinion: Its better not to use any other custom alert boxes.
Wednesday, August 13, 2008
Change / Increase session timeout in php
Projects using login may have the problem of expiring sessions in short time.
How to increase the session timeout in PHP?
use this as first line - before session_start
ini_set('session.cookie_lifetime',(3600*2));
In some servers it may not work.... BUT using .htaccess file it is working very fine.
Just place these lines in the .htaccess file and put the file in your root directory.
php_value session.cookie_lifetime 3600
php_value session.gc_maxlifetime 3600
and note these parameters are in seconds.
Then how to check the current session timeout?
use this:
printf("cookie: %s, gc: %s", ini_get('session.cookie_lifetime'), ini_get('session.gc_maxlifetime'));
Thats all.
How to increase the session timeout in PHP?
use this as first line - before session_start
ini_set('session.cookie_lifetime',(3600*2));
In some servers it may not work.... BUT using .htaccess file it is working very fine.
Just place these lines in the .htaccess file and put the file in your root directory.
php_value session.cookie_lifetime 3600
php_value session.gc_maxlifetime 3600
and note these parameters are in seconds.
Then how to check the current session timeout?
use this:
printf("cookie: %s, gc: %s", ini_get('session.cookie_lifetime'), ini_get('session.gc_maxlifetime'));
Thats all.
Subscribe to:
Posts (Atom)