javivilchis Posted May 9, 2009 Share Posted May 9, 2009 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>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/ Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 To deactivate any input from the user you need a cleint side script (javascript). PHP will not do this for you, try asking in the javascript forum! Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830266 Share on other sites More sharing options...
ILMV Posted May 9, 2009 Share Posted May 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830270 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 Thank you guys, How will I call the function within the php code? to work on the dynamic generated pages? Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830284 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 The same as you would with html, just put it in the right place and echo it out as usual Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830285 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 i've added the javascript to the index.php then calling the function onload inside the body tag and it is still no result Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830298 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 Still sounds like a client side problem, post your code Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830301 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 FYI, i'm using firefox in a macbook pro. should I test it in windows? Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830302 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 Still sounds like a client side problem, post your code It shouldn't matter where you test as you want it to work everywhere right? Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830303 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 <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> Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830304 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 You're <html> tag is in the wrong place Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830308 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 o.k. I've placed it all the way to the top. Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830311 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 <script language="JavaScript"> should be <script type="text/javascript"> Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830313 Share on other sites More sharing options...
sKunKbad Posted May 9, 2009 Share Posted May 9, 2009 No matter what javascript you use to "protect" your images, you will never be able to stop people from stealing them. They will just disable javascript. Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830314 Share on other sites More sharing options...
javivilchis Posted May 9, 2009 Author Share Posted May 9, 2009 Gevans, i've changed it to <script type="text/javascript"> still nothing. Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830315 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 OK, When you've got the page up in your browser view source. If everything is as it should be then you have a javascript issue. I'd ask over in the javascript forum or look for a differnet script Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830316 Share on other sites More sharing options...
gevans Posted May 9, 2009 Share Posted May 9, 2009 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") Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830317 Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2009 Share Posted May 9, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-830320 Share on other sites More sharing options...
javivilchis Posted May 11, 2009 Author Share Posted May 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157485-deactivating-right-mouse-click-in-a-php-gallery/#findComment-831306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.