Jump to content

how to protect php source code...


Go to solution Solved by kicken,

Recommended Posts

How can i protect my php source code from being hacked... if i used this type of code in my page....

<?php
require_once '../dbconfig.php';
require_once 'header.php';
 $adi = $_REQUEST['aid'];
$date = date("Y-m-d");
 $uid =  $_SESSION['user_id1'];
$a = mysql_query("SELECT * FROM ad_clk_hits WHERE user_id='$uid' AND date='$date' AND adv_id='$adi'") or die(mysql_error());
if(mysql_num_rows($a)){
    echo "<div id='view_ad'>   
   <div id='view_ad_text_error'><img src='images/ebab_mbmcp_ico_6.png' class='error_image' />You have already visited this advertisement today</div>
</div>";    
}
else{
    $b = mysql_query("SELECT * FROM ad_clk WHERE id='$adi'") or die(mysql_error());
    while ($row = mysql_fetch_array($b)) {
    $imp = $row['impression'];
    $link = $row['link'];
    $money = $row['money'];
}
$newimp = $imp - 1;
$c = mysql_query("UPDATE ad_clk SET impression='$newimp' WHERE id='$adi'") or die(mysql_error());
$d = mysql_query("SELECT * FROM users WHERE user_id='$uid'") or die(mysql_error());
while ($re = mysql_fetch_array($d)){
    $money1 = $re['money'];
}
$newmoney = $money + $money1;
$e = mysql_query("UPDATE users SET money='$newmoney' WHERE user_id='$uid'") or die(mysql_error());
$f = mysql_query("INSERT INTO ad_clk_hits (id,user_id,date,adv_id) VALUES ('','$uid','$date','$adi')") or die(mysql_error());
?>
<!-- Show magical div -->
<script type="text/javascript">
    function showIt() {
      document.getElementById("view_ad_text_right").style.display = "block";
    }
// 1000 = 1 sec | 60000 is 1 minute
    </script>
<!-- END Show magical div -->
<body onLoad='setTimeout("showIt()", 16000);'></body>

<!-- Magic DIV -->
<div id="view_ad">
    <script type="text/javascript">
    $(document).ready(function () {
  setTimeout(function () {
      $('#view_text').hide();
  }, 6000);
});
</script>
<div id="view_text">Please wait for 15 secs</div>
<div id='view_ad_text_right' style="display:none;">Thank you for visiting...</div>
</div>
<!-- END Magic DIV -->

<iframe src="<?php echo $link; ?>" width="100%" height="100%" /></iframe>
<?php
}
?>

Any help will bew grately appreciated....

Link to comment
https://forums.phpfreaks.com/topic/277644-how-to-protect-php-source-code/
Share on other sites

  • Solution

Make sure your variables that are used in the SQL queries have been escaped using mysql_real_escape_string, or even better, update your code to use PDO and prepared statements.

 

Secondly, rather than do some SELECT's to get $money and $money1 you can do the whole thing in a single UPDATE query which would prevent race-conditions resulting in a bad money value.

 

My syntax may be off some as I typically used SQL Server that has a different syntax. Check the mysql manual for syntax details

UPDATE users u
INNER JOIN ad_clk a ON id=$adi
SET
   u.money=u.money+a.money
WHERE
   u.id=$uid
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.