CONTEST - Submit your PHP [CLOSED]

Here you will find the latest competition contest and the entries for them. Hurry and submit yours now.
5 posts Page 1 of 1
Contributors
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 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 7: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
Site Admin
Posts: 4385
Joined: Tue Aug 04, 2009 1:47 am

Re: CONTEST - Submit your PHP
CodenStuff
Here's one to get the Video ID from a Youtube 'watch' URL.

Example URL:
https://www.youtube.com/watch?v=IgQWRuo2D6w
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
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: CONTEST - Submit your PHP
AnoPem
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
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: CONTEST - Submit your PHP
smashapps
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
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: CONTEST - Submit your PHP
smashapps
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!
5 posts Page 1 of 1
Return to “Competitions”