Jump to content

Recommended Posts

hello all,

 

I have a function that generates images from the image files inside a folder, everything works fine. However, I will like to add a code that will block the right mouse click or better yet, I will like to deactivate the download picture option to prevent people from stealing the images or copying them. Any suggestions in how to do this? the pages are dynamically created, i've tried using javascript but the dynamic pages do not pick it up. here is the function that generates the images:

function showBigImg($aPath, $aIdx)
{
  global $files, $isDir; 

  echo "<center>";
  echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";

  if($isDir[$files[$aIdx]]) {
    showDir($aPath, $files[$aIdx]);
  } else {
    // generate the html
    echo "<td>";
    echo "<center><img border=\"0\" src=\"".$aPath.$files[$aIdx]."\"></img></center>";
    echo "</td>";

    echo "</table>";
    echo "</center>";
  }
}

This is not a PHP problem, also a quick Google search will fin what you are looking for.

 

Check out this example, http://www.hypergurl.com/norightclick.html

 

But let me suggest that this will not prevent people from being able to download your images, it will just slightly deter them.

 

 

ILMV

<head>

<script language="JavaScript"> 

function noway(go) { if 
(document.all) { if (event.button == 2) { alert(popup); return false; } } if (document.layers) 
{ if (go.which == 3) { alert(popup); return false; } } } if (document.layers) 
{ document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=noway;
</script>
<script language="JavaScript1.1"> 
// distributed by http://www,hypergurl.com 
var debug = true; function 
right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which 
== 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' 
&& (event.button == 2 || event.button == 3)) { alert('This Page is fully 
protected!'); return false; } return true; } document.onmousedown=right; if (document.layers) 
window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right;</script>

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">



<title>Hyacinth Vase Collection</title>

<?php



  if (is_file("./settings.php")) {
    include("settings.php");
  }
  if (is_file("./styles.php")) {
    include("styles.php");
  }

  global $g_bgcolor, $g_titlecolor, $g_desccolor;

?>

<style type="text/css">
@charset "UTF-8";

body 
	{
	font-family: Arial, Helvetica, sans-serif;
	color:#333333;
	size: 12px;
	background-color:#ffffb7;
	padding:0px;
	margin:0px;
	}
.mainpage {
	background-color:#ffffff;
	padding:5px;
	vertical-align:top;

	}
.header	{
	background-color:#ffffb7;
	}
.logo   {
	background-color:#ffffb7;
	padding:10px;
	font-family:Arial, Helvetica, sans-serif;
	color:#ffffff;
	font-size:16px;
	}

#header {
  float:left;
  width:100%;
  background-color:#ffffb7;
  line-height:normal;
  }
#header ul {
  margin:0;
  padding:0px 0px 0;
  list-style:none;
  }
#header li {
  float:left;
  background-color:#ffffb7;
  margin:0;
  padding:0 0 0 53px;
  }
#header a {
  float:left;
  display:block;
background-color:#ffffb7;
background-image:URL(..images/buttonback.png);

  padding:11px 40px 11px 0px;
  text-decoration:none;
  font-weight:bold;
  color:#333333;
  }
/* Commented Backslash Hack
   hides rule from IE5-Mac \*/
#header a {float:none;}
/* End IE5-Mac hack */
#header a:hover {
  color:#000000;
  }
#header #current {
  background-image:url("left_on.gif");
  }
#header #current a {
background-color:#ffe600;
padding-left:14px;
  color:#ffffff;
  }

</style>

</head>

<?php
  
  // in case register global is off
  foreach($HTTP_GET_VARS as $key => $val) {
     $$key = $val;
     global $$key;
  }

  global $files, $isDir, $g_twidth, $g_cols, $g_rows, $g_title, $g_desc, $g_dispFn, $g_sortByFn, $g_folderImg, $g_showInPopup, $g_popupWidth, $g_popupHeight;

  include("func.php");
  $path = adjustPath($path);
  if(!$page)
    $page = 0;


  if(!$g_cols)
    $g_cols = 4;
  if(!$g_rows)
    $g_rows = 1;
  if(!$g_title)
    $g_title = "Image Gallery";
  if(!$g_twidth)
    $g_twidth = 100;

  $files = array();
  $isDir = array("." => false);
  @readFiles($path, $files, $isDir);
?>

<html>

<body <?php if($g_textcolor != "") echo "text=\"$g_textcolor\" ";
        if($g_linkcolor != "") echo "link=\"$g_linkcolor\" ";
        if($g_vlinkcolor != "") echo "vlink=\"$g_vlinkcolor\" "; ?> onload="noway()" ondragstart="return false" onselectstart="return false">
        
        
        <table width="800" height="768" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
<tr>
  <td height="88px" class="logo">
		<img src="../images/hvclogo.png">
            
            </td>
  </tr>
<tr>
	<td height="43" class="header">
        
         <div id="header">
  <ul>
    <li><a href="../index.php">Home</a></li>
    <li><a href="../about.php">About Vase Collection</a></li>
    <li><a href="../history.php">History</a></li>
    <li id="current"><a href="../imagegallery2/index.php">Gallery</a></li>

    <li><a href="contact.php">Contact</a></li>
  </ul>
</div>

        
        
		</td>
</tr>
<tr>
	<td width="800px" height="590px" class="mainpage">
	  <div align="center" class="headline"><?php echo $g_title; ?></div>

      
      <div align="center" class="desc"><?php echo $g_desc; ?></div>
	<p>
	<div align="center">
        <a href="../red/index.php"><img src="../images/red.png" border="0"></a> |<a href="../orange/index.php"><img src="../images/orange.png" border="0"></a> | <a href="../yellow/index.php"><img src="../images/yellow.png" border="0"></a> |<a href="../green/index.php"><img src="../images/green.png" border="0"></a> |<a href="../blue/index.php"><img src="../images/blue.png" border="0"></a> |<a href="../purple/index.php"><img src="../images/purple.png" border="0"></a> |
        
         <a href="../white/index.php"><img src="../images/white.png" border="0"></a> |     <a href="../clear/index.php"><img src="../images/clear.png" border="0"></a>
      
        
	<?php
		@showPageLinks($path, count($files), $page, $idx,
			$g_cols, $g_rows);
	?>
	</div>
        
        
        <?php
		if ($idx == "") {
		  @showImgTable($path, $files, $isDir, $page,
			$g_cols, $g_rows);
		} else {
		  @showBigImg($path, $idx);
		}
	?>
        </td>
</tr>
<tr>
	<td>
		<img src="../images/bottom.png" width="800" height="27" alt=""></td>
</tr>
<tr>
	<td>
		<p>Number of guests visiting my site
: <?
include ("counter.php");
?></p></td>
</tr>
</table>
        



</body>

</html>

If you want to try a different one try this...

 

function clickIE() 
{
  if (document.all)
  {
    return false;
  }
} 
function clickNS(e) 
{
  if (document.layers||(document.getElementById&&!document.all))
  {
    if (e.which==2||e.which==3)
    {
      return false;
    }
  }
}
if (document.layers)
{
  document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;
}
else
{
  document.onmouseup=clickNS;document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")

Your php code has the following problems -

 

1) The global keyword only has meaning inside of a function definition (and it should not even be used there.) All the lines of code you posted with global in them don't do anything and the time you spent typing them is time lost out of your life that you will never get back.

 

2) $HTTP_GET_VARS was depreciated a long time ago (some time in the year 2002), they are tuned off by default in php5, and they have been completely removed in php6. You should be using $_GET. If you are still using php4, the end of life and end of support for php4 was more than one year ago. You should upgrade to php5.

 

3) Your foreach() loop that blindly populates program variables from  $HTTP_GET_VARS/$_GET variables will allow a hacker to set your existing program variables to anything he wants. For the posted code, that would be anything in your settings.php file. But if you are using that same loop in other code, it could allow a hacker to become logged in as an administrator to your script.

  A) You should use the specific $_GET variable that you expect data in, or

  B) use a unique prefix on the variable name so that there is no chance of overwriting existing variables - you can use the extract() function with the second parameter set to EXTR_PREFIX_ALL and with a unique prefix.

 

4) All the @ in the code to suppress the display of errors should be removed. If your code is producing errors you should find the reason why and fix it. On a live server you should have the display_errors setting OFF to prevent the display of any unexpected errors, but code should not normally produce any errors during its execution. Each error that is encountered must still be handled by php, so using the @ to hide the error messages would give the appearance of code running slow and probably giving unexpended results without telling you why.

o.k..

 

it was definitely the javascript that caused this not to work, everything else works just fine. I will upgrade the code to php 5 standards. Thanks to gevans for the javascript it worked like a charm.

 

thank you all again,

 

jav

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.