Hack Forums
[PHP] Licensing System - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] Licensing System (/showthread.php?tid=5107347)

Pages: Pages 1 2


Licensing System - Sevn™ - Dec 24, 2015

I'm slowly starting to understand and learn PHP/SQL so i wrote up this licensing system.

Basically what this does is uses an api to check if the key is valid or not.

Features:
Login with license key.
View content for people that are logged in only.
Logout.
API System
Check if key is valid

Images:
Spoiler (Click to View)

Installation:

Upload the SQL file to PHPMyAdmin.
Make sure to edit the db.php file in /inc with your database details.


Download:

https://www.dropbox.com/s/8no6du6gf23mw6q/license.rar?dl=0


🤝


* - Sakuto - Dec 25, 2015

Use github for this kind of share, way better than an archive (:


* - Øbscured - Dec 25, 2015

(Dec 24, 2015 09:15 PM)Sevn™ Wrote:  [FONT=Century Gothic]I'm slowly starting to understand and learn PHP/SQL so i wrote up this licensing system.

getting ready to venture down the same path.
ill check this out, thanks.

+1 to the github thing.


* - alma143 - Dec 25, 2015

Error
SQL query:

/*!40101 SET NAMES utf8mb4 */;


MySQL said: Documentation

#1115 - Unknown character set: 'utf8mb4'


* - Grammar Rays - Dec 25, 2015

(Dec 25, 2015 12:16 PM)alma143 Wrote:  Error
SQL query:

/*!40101 SET NAMES utf8mb4 */;


MySQL said: Documentation

#1115 - Unknown character set: 'utf8mb4'

You need to update your MySQL version. You on shared hosting or a VPS? Are you able to access the host server?

EDIT: You may be able to change it to utf8 but maybe ask author first as depends how this was developed.


* - alma143 - Dec 25, 2015

ok ill try and post result again here..thanks bro


* - mothh - Dec 26, 2015

What kind of MySQL extension did you use? PDO or MySQLi?


* - Sevn™ - Dec 26, 2015

(Dec 26, 2015 06:15 AM)mothh Wrote:  What kind of MySQL extension did you use? PDO or MySQLi?

PDO :)


* - mothh - Dec 26, 2015

I am going to take a look at it and I will let you know what I think of your code.




I see that you do your if statements and stuff like that like this:
PHP Code

<?php 
if()
{
    
//Code here
} 

In my personal opinion it looks nicer and more clean if you do it like this:
PHP Code

<?php 
if(){
    
//Code here
} 

That way you don't have one line for only one character and you keep your amount of lines needed smaller.

Then to the things that you can improve code wise.

I see you do your database queries like this:
PHP Code

<?php 
$SQLGetInfo 
-> execute(array(':key' => $_GET['key']));
 
$keyinfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC); 

You don't need to put spaces between the ->, so instead I would make them like this:
PHP Code

<?php 
$SQLGetInfo
->execute(array(':key' => $_GET['key']));
 
$keyinfo = $SQLGetInfo->fetch(PDO::FETCH_ASSOC); 

A small note, in the newer PHP version you don't need to do array() anymore, you can just do [] to make an array.




A critical error I see is that you don't start your session at the beginning of the document, you NEED to do this, what I suggest is that you put session_start(); on the second line of your config file, just after you opened php.

You also did not include header.php in the download.




On line 79 of index.php I see this:
PHP Code

<?php 
if($password == ''){
            echo 
"Please enter a key.";
        } 

You should change that to the following because there is a function for it:
PHP Code

<?php 
if(empty($password)){
            echo 
"Please enter a key.";
        } 

I also see that you make a session of the password:
PHP Code

<?php 
isset($_SESSION['password']) 

That is just plain bad and I hope you understand why.

Other than that for one of your first scripts it doesn't look all to bad.

If you have any questions, feel free to ask me.


* - Kedox - Dec 26, 2015

(Dec 26, 2015 08:12 AM)mothh Wrote:  I am going to take a look at it and I will let you know what I think of your code.




I see that you do your if statements and stuff like that like this:
PHP Code

<?php 
if()
{
    
//Code here
} 

In my personal opinion it looks nicer and more clean if you do it like this:
PHP Code

<?php 
if(){
    
//Code here
} 

That way you don't have one line for only one character and you keep your amount of lines needed smaller.

Then to the things that you can improve code wise.

I see you do your database queries like this:
PHP Code

<?php 
$SQLGetInfo 
-> execute(array(':key' => $_GET['key']));
 
$keyinfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC); 

You don't need to put spaces between the ->, so instead I would make them like this:
PHP Code

<?php 
$SQLGetInfo
->execute(array(':key' => $_GET['key']));
 
$keyinfo = $SQLGetInfo->fetch(PDO::FETCH_ASSOC); 

A small note, in the newer PHP version you don't need to do array() anymore, you can just do [] to make an array.

I used to think that, but I think it looks more professional the first way round. Probably because since I started learning some c#. Another reason I guess, is because it gives space between the statement and the code.

e.g

PHP Code

<?php 
if(true == true && false == false && 10 + 4 > 43 && isset($_GET["pizza"])){
    
$toppings = get_toppings($_GET["pizza"]);
    echo 
$toppings;
} 

PHP Code

<?php 
if(true == true && false == false && 10 + 4 > 43 && isset($_GET["pizza"]))
{
    
$toppings = get_toppings($_GET["pizza"]);
    echo 
$toppings;
} 

I guess it's your personal preference, but my opinion it looks a lot neater. You can't really judge code on the way they structure their statements.


* - Sakuto - Dec 26, 2015

No, in PHP it's convention, take a look here: http://www.php-fig.org/psr/psr-2/


* - PloxSource - Dec 26, 2015

(Dec 26, 2015 08:23 AM)theklaus101 Wrote:  I used to think that, but I think it looks more professional the first way round. Probably because since I started learning some c#. Another reason I guess, is because it gives space between the statement and the code.

e.g

PHP Code

<?php 
if(true == true && false == false && 10 + 4 > 43 && isset($_GET["pizza"])){
    
$toppings = get_toppings($_GET["pizza"]);
    echo 
$toppings;
} 

PHP Code

<?php 
if(true == true && false == false && 10 + 4 > 43 && isset($_GET["pizza"]))
{
    
$toppings = get_toppings($_GET["pizza"]);
    echo 
$toppings;
} 

I guess it's your personal preference, but my opinion it looks a lot neater. You can't really judge code on the way they structure their statements.

I agree, I think having whitespace makes your code neater and readable.


* - mothh - Dec 26, 2015

(Dec 26, 2015 04:58 PM)PloxSource Wrote:  I agree, I think having whitespace makes your code neater and readable.

Between $bla = 'bla' I agree, but with $bla->bla() I don't agree.


* - PloxSource - Dec 26, 2015

(Dec 26, 2015 05:21 PM)mothh Wrote:  Between $bla = 'bla' I agree, but with $bla->bla() I don't agree.

I guess I didn't explain myself properly :)

Yes I agree with you,

$user->user()

is better than

$user -> user()


* - mothh - Dec 26, 2015

(Dec 26, 2015 06:12 PM)PloxSource Wrote:  I guess I didn't explain myself properly :)

Yes I agree with you,

$user->user()

is better than

$user -> user()

What did you mean then?