Skip to content

Instantly share code, notes, and snippets.

View itskingori's full-sized avatar
🚢
Shipping

King'ori Maina itskingori

🚢
Shipping
View GitHub Profile
@itskingori
itskingori / modx-programmatic-user-login.php
Last active January 12, 2016 07:32
Log in a user programmatically in MODx, answer (hopefully) to a question posted in the forums here; http://forums.modx.com/thread/86714/is-it-possible-to-login-a-user-programmatically-in-frontend
<?php
$id = 1; // just an example ... use appropriate id
$user = $this -> modx -> getObject('modUser', $id);
if (!$user -> hasSessionContext('web')) {
$user -> addSessionContext('web');
}
@itskingori
itskingori / exercise01.php
Last active December 31, 2015 22:08
Showing text in a browser
<!DOCTYPE html>
<html>
<head>
<title>Exercise 01: Show text in a browser</title>
</head>
<body>
<?php
// Create a PHP page, with the standard HTML <head>, <title> and <body> tags.
// This is not strictly necessary but is good practice and should the first
@itskingori
itskingori / exercise02.php
Created December 20, 2013 06:47
Arithmetic Operators and Variables
<!DOCTYPE html>
<html>
<head>
<title>Exercise 02: Arithmetic Operators and Variables</title>
</head>
<body>
<?php
// Create the following variables:
// $x = 10;
@itskingori
itskingori / exercise03.php
Created December 20, 2013 06:52
Assigning Variables and Using Operators
<!DOCTYPE html>
<html>
<head>
<title>Exercise 03: Assigning Variables and Using Operators</title>
</head>
<body>
<?php
// Write a script to reproduce the output below
// Value is now 8.
@itskingori
itskingori / exercise04.php
Created December 20, 2013 06:53
Creating Arrays
<!DOCTYPE html>
<html>
<head>
<title>Exercise 04: Creating Arrays</title>
</head>
<body>
<?php
// Create array that holds all the provinces of Kenya and output them to the
// browser from top to bottom
@itskingori
itskingori / exercise05.php
Last active December 31, 2015 22:09
Manipulating Arrays
<!DOCTYPE html>
<html>
<head>
<title>Exercise 05: Manipulating Arrays</title>
</head>
<body>
<?php
// Create your array of 30 high temperatures then find the average high
// temp, the five warmest high temps and the five coolest high temps. Print
@itskingori
itskingori / exercise06.php
Created December 20, 2013 06:56
Multi-Dimensional Arrays
<!DOCTYPE html>
<html>
<head>
<title>Exercise 06: Multi-Dimensional Arrays</title>
</head>
<body>
<?php
// Create a multi-dimensional array called $multiCity. Here's the content
// for your array: City, Country, Continent; Tokyo, Japan, Asia; Mexico
<!DOCTYPE html>
<html>
<head>
<title>Exercise 07: Loops</title>
</head>
<body>
<?php
// Write 3 scripts that will print the letters of the alphabet to the browser using a;
// * For loop
@itskingori
itskingori / exercise08.php
Created December 20, 2013 06:58
Simple Functions
<!DOCTYPE html>
<html>
<head>
<title>Exercise 08: Simple function</title>
</head>
<body>
<?php
// Functions in PHP can help automate repetitive tasks and enable you to
// reuse code with a simple function call. For your first function, we'll
@itskingori
itskingori / exercise09.php
Created December 20, 2013 06:59
Function With Arguments
<!DOCTYPE html>
<html>
<head>
<title>Exercise 09: Function with arguments</title>
</head>
<body>
<?php
// First, create a function to accept two arguments, perform a calculation
// using them, and then return a sentence with the result to the browser.