Programming

You are not authorized to access when trying to connect to TFS account in Visual Studio 2015

Y

To solve this problem you have to clean the cache folder on your machine.

Press Win + R together to open the Run window

Type in %UserProfile%\AppData\Local and click on OK

Navigate to the Microsoft\Team Foundation\6.0\Cache folder and delete all contents

Restart Visual Studio and Re-Open your solution.
The error message will disappear and all should be working again.

How to embed images using PHPMailer

H

Use the AddEmbeddedImage method provided by the PHPMailer class.  eg. $mail->AddEmbeddedImage(‘test.gif’,’testImage’,’test.gif’); Parameters for AddEmbeddedImage($path, $cid, $name = ”, $encoding = ‘base64’, $type = ‘application/octet-stream’) $path = Path to the attachment $cid = Content ID of the attachment.  Use this to...

Comparison Operators

C

PHP comparison operators allows you to compare two values with each other. Below is a table of all the different comparison operators that are available for PHP Comparison Operators Example Name Result $a == $b Equal TRUE if $a is equal to $b. $a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4) $a != $b Not equal TRUE if $a is not equal to $b. $a...

How to subtract a number of days from todays date using PHP date function

H

$var = ‘2007-08-15’; $var_subtracted_date = date(‘Y-m-d’, strtotime(‘-2 days’, strtotime($var))); Explanation of PHP functions: 1) FUNCTION date DESCRIPTION string date ( string $format [, int $timestamp ] ) PARAMETERS USED IN THIS EXAMPLE Y = A full numeric representation of a year, 4 digits (Examples: 1999 or 2003) m = Numeric representation of a month, with...

How to print the contents of an array using PHP

H

//Array example $arr = array(‘one’,’two’,’three’,’four’); Use the print_r function. Example: print_r($arr); The example above will print out the following: Array ( [0] => one [1] => two [2] => three [3] => four ) NOTE: If you want to have the contents of the array displayed in a more readable format, add a echo...

How to get the Nameservers of a domain using PHP

H

Use the  dns_get_record function with type DNS_NS Example: //Add this piece of code to your PHP will $result = dns_get_record(‘yourdomain.com‘,DNS_NS); Execute the script //An array will be returned similar as below Array ( [0] => Array ( [host] => yourdomain.com [type] => NS [target] => ns1.yourdomain.com [class] => IN [ttl] => 70144 ) [1] => Array ( [host] =>...

What is the purpose of the & Ampersand in front of PHP Variables

W

What this does it creates a reference to the original variable and thus does not copy the value of the original variable. $original_var = 500; &$ref_var = $original_var; //This will print the value 500 echo  $ref_var; //Now we change the value of the original variable to 600 $original_var = 600; //Now we print the value of the reference variable, and the reference variable takes the value of...

How to embed images using PHPMailer

H

Use the AddEmbeddedImage method provided by the PHPMailer class. eg. $mail->AddEmbeddedImage(‘test.gif’,’testImage’,’test.gif’); Parameters for AddEmbeddedImage($path, $cid, $name = ”, $encoding = ‘base64’, $type = ‘application/octet-stream’) $path = Path to the attachment $cid = Content ID of the attachment.  Use this to...

How to solve error: ‘PHP Warning: DOMDocument::createElement(): unterminated entity reference’ when creating a new element using the DOMDocument object model

H

DOMDocument = Represents an entire HTML or XML document; serves as the root of the document tree.  (PHP 5) DOMDocument::createElement()  = Create new element node. (PHP 5) Now to the solution! Solution: Use the htmlentitites function to convert all applicable characters to HTML entities. $dom->createElement(‘value’, htmlentities($text_value)); htmlentitites = Convert all applicable...

How to remove values in one array from another array using PHP

H

Example: I have array A with values and another array B. I need to remove the values in array A from the values in array B.   Use the PHP function array_diff Description array array_diff ( array $array1 , array $array2 [, array $ … ] ) Compares array1  against array2  and returns the difference. Parameters array1 = The array to compare from array2 = An array to compare against Code...

How to remove the first element of an array using PHP and then storing the element in a variable

H

By using the PHP function ‘array_shift‘ we can remove the first value of an array array_shift – Shift an element off the beginning of array (PHP 4 & 5) Example: $array = array("apple","peach","pineapple","banana"); $first_element = array_shift($array); echo '<pre>'; print_r($array); echo '</pre>'; echo $first_element; In the above example we have an array with 4...

How to force a CSV file to download when clicking on a download link using PHP

H

Example: We have a CSV file called example.csv we want users to download to use as a template. Now some browsers will display the contents of the file instead of asking users to download the file. What we want to do is to force the downloadinstead of displaying the contents in the browser. Create a new PHP file called ‘download.php‘ Open the file for editing Copy the code below into...

How to convert all $_POST or $_GET values to Integers

H

By using the built-in PHP functions  array_map and intval. array_map = Applies the callback to the elements of the given arrays, this applies the function for each value of an array (PHP 4 >= 4.0.6, PHP 5) intval = Get the integer value of a variable (PHP 4, PHP 5) Examples: {codecitation style=”brush: PHP;”} $post_int = array_map(‘intval’, $_POST); //Converting every...

Script to resize PNG, JPG and GIF images using PHP keeping the aspect ratio

S

How this script works: What this script does, it resizes any PNG, JPG or GIF image to the given width and height and stores the image to a specified location. If the width is set to 0 it will automatically calculate the width by using the height given by keeping the aspect ratio the same is. The same goes for when the height is set to 0 and the width is given. NOTE: Make sure the GD libraries are...

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me