IT Questions and Answers :)

Wednesday, November 29, 2017

In PHP scripting, which expression will output $somestring to the browser, only if it contains a colon?

In PHP scripting, which expression will output $somestring to the browser, only if it contains a colon?


  • if (strpos($somestring,":")!==false) echo $somestring ;
  • if (strpos($somestring,":")==true) echo $somestring ;
  • if (strpos($somestring,":")!=false) echo $somestring ;
  • if (strpos($somestring,":")=true) echo $somestring ;             
In PHP scripting, which expression will output $somestring to the browser, only if it contains a colon?


EXPLANATION

The correct test is "!==false"
The strpos() function finds the position of the first occurrence of a string inside another string. In this example, it looks for the numeric position of the first occurrence of a colon if one is present, or a boolean false value if none is found.
PHP strings are zero-indexed, so a string starting with colon (:) will return a numeric zero from strpos(). However, as in most scripting languages, the variables are not strongly typed, zero and false being equivalent in logic tests.
Thus, a string starting with a colon would cause the zero output of strpos() to be interpreted as 'Not found' and nothing would be output to the browser.
The workaround is to use a literal boolean test, which is expressed with '===' or '!==' for equality or inequality as appropriate.
The '===' test cannot be used here, because a colon's presence is returned as an integer value, which is not literally a boolean value. Thus doing so would result in no output, ever. (False or an integer are never literally equal to true.)
The correct approach is therefore to ask, 'Is the value returned by strpos() NOT LITERALLY a BOOLEAN FALSE' -which yields true for colon present anywhere including first character, false for no colon. (Also false for a null string)
Incidentally, BASIC-like languages index strings from one, so the issue does not arise. Javascript indexes strings from zero, but search functions typically return -1 as the 'not found' response.
The lowdown:
if (strpos($somestring,":")!==false) echo $somestring ; // Yay! It worked. :)
if (strpos($somestring,":")=true) echo $somestring ;     // This is a syntax error.
if (strpos($somestring,":")===true) echo $somestring ; // Never outputs anything.
if (strpos($somestring,":")!=false) echo $somestring ;   // Fails if the colon is first char, otherwise works.
if (strpos($somestring,":")==true) echo $somestring ;   // Fails if the colon is first char, otherwise works.
Share:

In a Windows domain, using built in domain features, how can you easily stop malicious software/viruses/cryptolocker from running from the downloads folder, or temporary internet files?

In a Windows domain, using built in domain features, how can you easily stop malicious software/viruses/cryptolocker from running from the downloads folder, or temporary internet files?

  • Advanced Windows Firewall Settings
  • Fancy Antivirus Software
  • Train your users to be more careful
  • Apply a Software Restriction Policy GPO 
 
In a Windows domain, using built in domain features, how can you easily stop malicious software/viruses/cryptolocker from running from the downloads folder, or temporary internet files?

EXPLANATION

Using a software restriction Policy you can create a whitelist or blacklist policy of locations that software is allowed to launch from. This included applications, scripts and so on. You can easily block software from launching from anywhere within a users profile, including the downloads folder. If you want to get into the advanced settings, you can blacklist ALL software and provide a while list of hashes for applications on your domain. SRP is extremely powerful, and very user friendly to configure. It is a valuable tool to use in keeping your network safe.

SOURCE

https://technet.microsoft.com/en-us/library/cc786941(v=ws.10).aspx
Share:

Tuesday, November 28, 2017

How many channels are in a full T1 PRI trunk?

How many channels are in a full T1 PRI trunk?

  • 23
  • 6
  • 24
  • 32 

 

How many channels are in a full T1 PRI trunk?

 

EXPLANATION

T1 connections have 24 channels in total.

Typically, for T1 ISDN (CCS) protocols, 23 channels are used as B-channels and 1 channel is used as a D-channel. For this reason, the frame structure of a T1 PRI connection is said to be 23B+1D where the D-channel is located on timeslot 23 (channels numbered from 0 to 23) and the remaining channels are used as B-channels. Hence;
If you had an E1 PRI trunk, you would have 30 B channels and 2 D channels.

SOURCE

https://en.wikipedia.org/wiki/Primary_Rate_Interface
Share:

How do you delete a login on SQL Server?

How do you delete a login on SQL Server?

  • DISABLE LOGIN login_name
  • DELETE LOGIN login_name
  • A login cannot be deleted but only disabled
  • DROP LOGIN login_name

How do you delete a login on SQL Server?

EXPLANATION

In order to delete a login on SQL Server, you write "DROP LOGIN login_name."
Share:

Friday, November 24, 2017

What is the minimum size of the IPv6 packet header?

What is the minimum size of the IPv6 packet header?


  • 40 octets
  • 36 octets
  • 32 octets
  • 48 octets             
What is the minimum size of the IPv6 packet header?

EXPLANATION

The IPv6 packet header has a minimum size of 40 octets. Options are implemented as extensions. This provides the opportunity to extend the protocol in the future without affecting the core packet structure.
RFC 2460; Internet Protocol, Version 6 (IPv6) Specification, S. Deering, R. Hinden (December 1998)
https://en.wikipedia.org/wiki/IPv6
Share:

Popular Posts