Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Licensing System

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/8no6du6gf23mw6...e.rar?dl=0


🤝
Use github for this kind of share, way better than an archive (:
(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.
Error
SQL query:

/*!40101 SET NAMES utf8mb4 */;


MySQL said: Documentation

#1115 - Unknown character set: 'utf8mb4'
(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.
ok ill try and post result again here..thanks bro
What kind of MySQL extension did you use? PDO or MySQLi?
Sometimes a fail leads to the solution.
(Dec 26, 2015 06:15 AM)mothh Wrote:  What kind of MySQL extension did you use? PDO or MySQLi?

PDO :)
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.
Sometimes a fail leads to the solution.
(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.
No, in PHP it's convention, take a look here: http://www.php-fig.org/psr/psr-2/
(Dec 26, 2015 08:23 AM)Kedox 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.
(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.
Sometimes a fail leads to the solution.
(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()
(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?
Sometimes a fail leads to the solution.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by moosa666Oct 31, 2016 02:45 PM 2 311 Oct 31, 2016 02:45 PM
Last Post: moosa666
[PHP] by GhostProtocolMar 12, 2015 07:45 AM 4 193 Mar 12, 2015 07:45 AM
Last Post: GhostProtocol
[PHP] by bourdJun 22, 2014 06:33 AM 203 9,383 Jun 22, 2014 06:33 AM
Last Post: bourd