• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2025 Replies
  • 331 Replies
    1928 Replies
Our minions are trying to make the site more secure by encasing the server in a cage made of solid SSL-ium which may throw up some issues when using the site for the next few hours. Bear with us while we weld this thing together and we are sorry for any inconvenience this may cause.

CONTEST - Submit your PHP [CLOSED]

User avatar
smashapps
Coding Guru
Posts: 960

CONTEST - Submit your PHP [CLOSED]

Thu Nov 03, 2016 10:27 am

Hey guys,

I have an AWESOME prize to give away to you folks! Get excited for this one :D

Details:

Ends 17th November 2016

I will pick a winner myself

How to enter:

Submit your favourite PHP snippets. Simple. I am doing a lot of PHP programming at the moment and it would be nice to have a few examples up my sleeve if I need it.
Any snippet you submit will not be used commercially or redistributed so don't worry.

Here's the good part!

You will receive a copy of:

Lumino City
Broken Age
Titan Souls



I have played Broken Age on PC as I bought a copy when it was released and it's a really fun, challenging game that requires you to pay a lot of attention to detail. At least I had to anyway lol

If I haven't been clear on anything just ask and I will explain myself, but all you need to do is submit your PHP snippet and have your chance to win those three games :)
Last edited by smashapps on Fri Nov 18, 2016 8:14 am, edited 1 time in total.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!

User avatar
CodenStuff
Site Admin
Posts: 4359

Re: CONTEST - Submit your PHP

Fri Nov 04, 2016 5:28 pm

Here's one to get the Video ID from a Youtube 'watch' URL.

Example URL:
This is the code:

Code: Select all

function youtubevideoid($videourl)
{
if (preg_match('![?&]{1}v=([^&]+)!', $videourl . '&', $m))
    return $m[1];	
}
Usage:

Code: Select all

youtubevideoid("https://www.youtube.com/watch?v=IgQWRuo2D6w");
Will return:
IgQWRuo2D6w
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.

User avatar
AnoPem
VIP - Donator
Posts: 441

Re: CONTEST - Submit your PHP

Sat Nov 05, 2016 12:04 am

Heres my no database required login

I was bored one day and decided to make this login system that doesnt require any database.
It saves all userdata to a file, of own choice with encrypted names and passwords

I made it just for fun to check out some functions of php

Class: Rollover to view spoiler

Code: Select all

<?php
	class user {
		
		private $credentials_file;
		
		public function __construct($credentials_file){
			$this->credentials_file = $credentials_file;
			if(!file_exists($credentials_file)){
				file_put_contents($credentials_file, serialize(array()));
			}
		}
		function salt($length){
			$output = '';
			$i = 0;
			$chars = array_merge(range('A','Z'), range('a','z'), range('0','9'));
			$count = count($chars) - 1;
			while($i < $length){
				$output .= $chars[mt_rand(0,$count)];
				$i++;
			}
			return $output;
		}
		function encrypt($input, $key) {
			if (strlen($key) >= 33){
				$key = substr($key, 0, 32 - strlen($key));
			}
			$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
			$iv = mcrypt_create_iv($size, MCRYPT_RAND);
			$output = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, utf8_encode($input), MCRYPT_MODE_ECB, $iv);
			return $output;
		}
		function decrypt($input, $key) {
			if (strlen($key) >= 33){
				$key = substr($key, 0, 32 - strlen($key));
			}
			$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
			$iv = mcrypt_create_iv($size, MCRYPT_RAND);
			$output = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $input, MCRYPT_MODE_ECB, $iv);
			return $output;
		}
		function create($username, $password, $salt){
			$credentials_file = $this->credentials_file;
			$username = $this->encrypt($username, $salt);
			$password = $this->encrypt($password, $salt);
			$credentials = file_get_contents($credentials_file);
			$credentials = unserialize($credentials);
			if(!array_key_exists($username, $credentials)){
				$credentials[$username] = $password;
				$output = array("status" => true, "reason" => "User created");
			} else {
				$output = array("status" => true, "reason" => "User already exists");
			}
			$credentials = serialize($credentials);
			file_put_contents($credentials_file, $credentials);
			return $output;
		}
		function remove($username, $password, $salt){
			$credentials_file = $this->credentials_file;
			$username = $this->encrypt($username, $salt);
			$password = $this->encrypt($password, $salt);
			$credentials = file_get_contents($credentials_file);
			$credentials = unserialize($credentials);
			if(array_key_exists($username, $credentials)){
				if($credentials[$username] == $password){
					unset($credentials[$username]);
					$credentials = serialize($credentials);
					file_put_contents($credentials_file, $credentials);
					$output = array("status" => true, "reason" => "User succesfully removed");
				} else {
					$output = array("status" => true, "reason" => "Wrong password");
				}
			} else {
				$output = array("status" => true, "reason" => "User dosent exists");
			}
			return $output;
		}
		function login($username, $password, $salt){
			session_start();
			$credentials_file = $this->credentials_file;
			$original_username = $username;
			$username = $this->encrypt($username, $salt);
			$password = $this->encrypt($password, $salt);
			$credentials = file_get_contents($credentials_file);
			$credentials = unserialize($credentials);
			if(array_key_exists($username, $credentials)){
				if($credentials[$username] == $password){
					$_SESSION['auth'] = 2;
					$_SESSION['username'] = $original_username;
					$output = array("status" => true, "reason" => "User succesfully logged in");
				} else {
					$output = array("status" => true, "reason" => "Wrong password");
				}
			} else {
				$output = array("status" => true, "reason" => "User dosent exists");
			}
			return $output;
		}
	}
?>
[/spoiler]
Usage: Rollover to view spoiler

Code: Select all

<meta charset="UTF-8">
<?php
	require_once('classes/user.php');
	$user = new user('permission.ini');
	$salt = "TYe0Z8TEHvJElf0eHs3iUai2GjU4WCG7";
	
	/*	//Create user */
	if(isset($_GET['username']) != '' && isset($_GET['password']) != ''){
		$username = $_GET['username'];
		$password = $_GET['password'];
		
		$create = $user->create($username, $password, $salt);
		if($create['status']){
			echo $create['reason'];
		}
	}
	
	
	echo '<br>';
	
	
	/*	//User login */
	if(isset($_GET['username']) != '' && isset($_GET['password']) != ''){
		$username = $_GET['username'];
		$password = $_GET['password'];
		
		$remove = $user->login($username, $password, $salt);
		if($remove['status']){
			echo $remove['reason'];
		}
	}
	
	
	echo '<br>';
	
	
	//User remove 
	if(isset($_GET['username']) != '' && isset($_GET['password']) != ''){
		$username = $_GET['username'];
		$password = $_GET['password'];
		
		$login = $user->remove($username, $password, $salt);
		if($login['status']){
			echo $login['reason'];
		}
	}
	
	echo '<br><br><br>';
	
	@session_start();
	var_dump($_SESSION);
	
	
?>
[/spoiler]
Image

User avatar
smashapps
Coding Guru
Posts: 960

Re: CONTEST - Submit your PHP

Fri Nov 11, 2016 4:25 am

Still 6 days to go if you want to enter the contest :)
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!

User avatar
smashapps
Coding Guru
Posts: 960

Re: CONTEST - Submit your PHP

Fri Nov 18, 2016 8:10 am

Okay guys the contest is over!

the winner is CodenStuff, congratulations. Sorry AnoPem :)
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!

Post Reply

Return to “Competitions”