You've already forked OpenShorte.old
							
							Renamed "includes" to "templates" Added .htaccess to redirect requests to index.php Added function to split request URL into array Corrected locations in scripts and pages
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
|     require_once ( 'config.php' );
 | |
|     function db_connect ( ) {
 | |
|         global $config;
 | |
|         $connection = new MySQLi ( $config [ 'db' ] [ 'host' ], $config [ 'db' ] [ 'username' ], $config [ 'db' ] [ 'password' ], $config [ 'db' ] [ 'name' ], $config [ 'db' ] [ 'port' ] );
 | |
|         if ( $connection->connect_errno ) {
 | |
|             die ( "Database connection failed." );
 | |
|         }
 | |
|         return $connection;
 | |
|     }
 | |
|     function db_prepare ( MySQLi $connection, string $query ) {
 | |
|         if ( ! ( $statement = $connection -> prepare ( $query ) ) ) {
 | |
|             die ( "Prepare failed: (" . $connection->errno . ") " . $connection->error );
 | |
|         }
 | |
|         return $statement;
 | |
|     }
 | |
|     function db_bind ( MySQLi_stmt $statement, array $params ) {
 | |
|         if ( ! call_user_func_array ( array ( $statement, "bind_param" ), array_merge ( $params [ 0 ], $params [ 1 ] ) ) ) {
 | |
|             die ( "Binding parameters failed: (" . $statement->errno . ") " . $statement->error );
 | |
|         }
 | |
|     }
 | |
|     function db_execute ( $statement ) {
 | |
|         if ( ! $statement->execute ( ) ) {
 | |
|             die ( "Execute failed: (" . $statement->errno . ") " . $statement->error );
 | |
|         }
 | |
|     }
 | |
|     function split_uri_array ( string $php_self, string $request_uri ) : Array {
 | |
|         $uri = substr ( $request_uri, strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ), strlen ( $request_uri ) - strlen ( substr ( $php_self, 0, strrpos ( $php_self, 'index.php' ) ) ) );
 | |
|         $arr = Array ( );
 | |
|         $last_arg_pos = 0;
 | |
|         for ( $i = 1; $i < ( strlen ( $uri ) ) - 1; $i ++ ) {
 | |
|             if ( substr ( $uri, $i, 1 ) == "/" && substr ( $uri, $i + 1, 1 ) != "/" && substr ( $uri, $i - 1, 1 ) != "/" ) {
 | |
|                 $arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos);
 | |
|                 $last_arg_pos = $i + 1;
 | |
|             }
 | |
|         }
 | |
|         $arr [ ] = substr ( $uri, $last_arg_pos, $i - $last_arg_pos + 1);
 | |
|         return $arr;
 | |
|     }
 | |
| ?>
 |