• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Znote AAC] Redeem a coupon system

raf

Active Member
Joined
Jan 10, 2011
Messages
260
Reaction score
37
Location
Warsaw, PL
How is the redeem going for GesiorAAC, can I help you with anything? :)
haven't been working on redeem part lately, but you reminded me, i was about to work on it today so i'm gonna continue doing this, if i step into any issues, i will post them here :)


--edit
first thing i occured is
PHP:
       // ipv6 fixes
        if (Visitor::getVisitorIP()) == "::1") {
          $ip = ip2long("127.0.0.1");
        } else {
          $ip = ip2long(Visitor::getVisitorIP());
        }
It's just not showing a page.
 
Last edited:

raf

Active Member
Joined
Jan 10, 2011
Messages
260
Reaction score
37
Location
Warsaw, PL
PHP:
<?php
if(!defined('INITIALIZED'))
    exit;

if($logged){
  if(isset($_POST['code'])) {

    $code = mysql_real_escape_string($_POST['code']);
    $query = $SQL->query('SELECT * FROM `__cornex_redeem` WHERE `code` = '.$code.' LIMIT 1;');


    // Key exist in database
    if (mysql_num_rows($query) !== 1) {
      // $query = $query[0];

      $used = ($query['used'] == 1);

      if ($used) {
        $error[] = 'Key has already been used';
      }

      if (!empty($error)) {

        foreach ($error as $err) {
          echo $err.'<br>';
        }

      }


      if (empty($error)) {
        $time = time();
        $code = $query['code'];
        $points = $query['points'];
        $SQL->query('UPDATE `__cornex_redeem` SET `used`=1 , `time`='.$time.' WHERE `code`='.$code.';');
        $account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $points);
        $account_logged->save();

        echo 'Amount of '.$points.' points has been added to your account!';
      }

    } else {
      echo 'Key is not valid';
    }

  }
$accid = $account_logged->getID();
$main_content .= '
<form action="" method="POST">

    <input type="text" name="code">
    <input type="submit" value="Redeem">

</form>';
} else {
    $main_content .= '
<div class="ui warning message">
  <div class="header">
    You dont have permission to do that!
  </div>
</div>
    ';
}

This is so far what i've got, i don't know why but it doesn't get amount of points from sql query, and it doesnt recognize the code.
 

Tarek1337

Legendary OT User
Joined
Jun 9, 2012
Messages
3,581
Solutions
3
Reaction score
1,163
Location
Sweden
haven't been working on redeem part lately, but you reminded me, i was about to work on it today so i'm gonna continue doing this, if i step into any issues, i will post them here :)


--edit
first thing i occured is
PHP:
       // ipv6 fixes
        if (Visitor::getVisitorIP()) == "::1") {
          $ip = ip2long("127.0.0.1");
        } else {
          $ip = ip2long(Visitor::getVisitorIP());
        }
It's just not showing a page.
I'm not pro. But what i see the page only shows if you have actived ipv6
 
OP
Cornex

Cornex

Web Developer
Staff member
Global Moderator
Joined
Jun 15, 2008
Messages
3,447
Solutions
5
Reaction score
1,163
Location
Sweden
PHP:
<?php
if(!defined('INITIALIZED'))
    exit;

if($logged){
  if(isset($_POST['code'])) {

    $code = mysql_real_escape_string($_POST['code']);
    $query = $SQL->query('SELECT * FROM `__cornex_redeem` WHERE `code` = '.$code.' LIMIT 1;');


    // Key exist in database
    if (mysql_num_rows($query) !== 1) {
      // $query = $query[0];

      $used = ($query['used'] == 1);

      if ($used) {
        $error[] = 'Key has already been used';
      }

      if (!empty($error)) {

        foreach ($error as $err) {
          echo $err.'<br>';
        }

      }


      if (empty($error)) {
        $time = time();
        $code = $query['code'];
        $points = $query['points'];
        $SQL->query('UPDATE `__cornex_redeem` SET `used`=1 , `time`='.$time.' WHERE `code`='.$code.';');
        $account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $points);
        $account_logged->save();

        echo 'Amount of '.$points.' points has been added to your account!';
      }

    } else {
      echo 'Key is not valid';
    }

  }
$accid = $account_logged->getID();
$main_content .= '
<form action="" method="POST">

    <input type="text" name="code">
    <input type="submit" value="Redeem">

</form>';
} else {
    $main_content .= '
<div class="ui warning message">
  <div class="header">
    You dont have permission to do that!
  </div>
</div>
    ';
}

This is so far what i've got, i don't know why but it doesn't get amount of points from sql query, and it doesnt recognize the code.

Yeah it has some errors, don't use mysql functions since they are depracted. Here you go:

PHP:
<?php
if(!defined('INITIALIZED'))
    exit;

if($logged){
  if(isset($_POST['code'])) {

    $code =  $SQL->quote($_POST['code']);
    $query = $SQL->query('SELECT * FROM `__cornex_redeem` WHERE `code` = '.$code.' LIMIT 1;');



    // Key exist in database
    if ($query->rowCount() >= 1) {
      // $query = $query[0];
      $result = $query->fetchAll(PDO::FETCH_ASSOC)[0];

      if ($result['used_by'] > 0) {
        $error[] = 'Key has already been used';
      }

      if (!empty($error)) {

        foreach ($error as $err) {
          echo $err.'<br>';
        }

      }


      if (empty($error)) {
        $time = time();
        $code = $result['code'];
        $points = $result['points'];
        $querys = sprintf('UPDATE `__cornex_redeem` SET `time`='.time().', `used_by`='.$account_logged->getId().' WHERE `code`="'.$result['code'].'" ');
        $SQL->query($querys);
        $account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $points);
        $account_logged->save();

        echo 'Amount of '.$points.' points has been added to your account!';
      }

    } else {
      echo 'Key is not valid';
    }

  }
$accid = $account_logged->getID();
$main_content .= '
<form action="" method="POST">

    <input type="text" name="code">
    <input type="submit" value="Redeem">

</form>';
} else {
    $main_content .= '
<div class="ui warning message">
  <div class="header">
    You dont have permission to do that!
  </div>
</div>
    ';
}
 

raf

Active Member
Joined
Jan 10, 2011
Messages
260
Reaction score
37
Location
Warsaw, PL
Nice!
Yeah it has some errors, don't use mysql functions since they are depracted. Here you go:

PHP:
<?php
if(!defined('INITIALIZED'))
    exit;

if($logged){
  if(isset($_POST['code'])) {

    $code =  $SQL->quote($_POST['code']);
    $query = $SQL->query('SELECT * FROM `__cornex_redeem` WHERE `code` = '.$code.' LIMIT 1;');



    // Key exist in database
    if ($query->rowCount() >= 1) {
      // $query = $query[0];
      $result = $query->fetchAll(PDO::FETCH_ASSOC)[0];

      if ($result['used_by'] > 0) {
        $error[] = 'Key has already been used';
      }

      if (!empty($error)) {

        foreach ($error as $err) {
          echo $err.'<br>';
        }

      }


      if (empty($error)) {
        $time = time();
        $code = $result['code'];
        $points = $result['points'];
        $querys = sprintf('UPDATE `__cornex_redeem` SET `time`='.time().', `used_by`='.$account_logged->getId().' WHERE `code`="'.$result['code'].'" ');
        $SQL->query($querys);
        $account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $points);
        $account_logged->save();

        echo 'Amount of '.$points.' points has been added to your account!';
      }

    } else {
      echo 'Key is not valid';
    }

  }
$accid = $account_logged->getID();
$main_content .= '
<form action="" method="POST">

    <input type="text" name="code">
    <input type="submit" value="Redeem">

</form>';
} else {
    $main_content .= '
<div class="ui warning message">
  <div class="header">
    You dont have permission to do that!
  </div>
</div>
    ';
}
lol, nicely done!

i've been troubleshooting with this for last 3 hours :D Was almost there, but you were ahead of me ;P
 
OP
Cornex

Cornex

Web Developer
Staff member
Global Moderator
Joined
Jun 15, 2008
Messages
3,447
Solutions
5
Reaction score
1,163
Location
Sweden
Nice!

lol, nicely done!

i've been troubleshooting with this for last 3 hours :D Was almost there, but you were ahead of me ;P

No problems! Remember to create your own thread with this gesior version so people don't miss it. Nice done :)
 
Top