Thursday, March 19, 2020

How to Set and Use Cookies in PHP

How to Set and Use Cookies in PHP As a website developer, you can use PHP to set cookies  that contain information about the visitors to your website. Cookies store information about a site visitor on the visitors computer that can be accessed upon a return visit. One common use of cookies is to store an access token so the user doesnt need to log in each time he visits your website. Cookies can also store other information such as the users name, the date of the last visit and shopping-cart contents. Although cookies have been around for years and most people have them enabled, some users either do not accept them because of privacy concerns or automatically delete them when their browsing session closes. Because cookies can be removed by a user at any time and are stored in a plain-text format, dont use them to store anything sensitive. How to Set a Cookie Using PHP In PHP, the setcookie() function defines a cookie. Its sent along with the other HTTP headers and transmits before the body of the HTML is parsed. A cookie follows the syntax: setcookie(name,value,expire,path,domain,secure,httponly); where name​ denotes the name of the cookie and ​value​ describes the cookies contents. ​For the setcookie() function, only the  name​ parameter is required. All other parameters are optional.   Example Cookie ​To set a  cookie named UserVisit in the visitors browser that sets the value to the current date, and further sets the expiration to be  in 30 days (2592000 60 seconds * 60 mins * 24 hours * 30 days), use the following PHP code: ?php $Month 2592000 time();//this adds 30 days to the current timesetcookie(UserVisit, date(F jS - g:i a), $Month);? Cookies must be sent before any HTML is sent to the page or they do not work, so the setcookie() function must appear before the html tag. How to Retrieve a Cookie using PHP To retrieve a cookie from the users computer upon the next visit, call it with the following code: ?phpif(isset($_COOKIE[UserVisit])){$last $_COOKIE[UserVisit];echo Welcome back! br You last visited on . $last;}else{echo Welcome to our site!;}? This code first checks if the cookie exists. If it does, it welcomes the user back and announces when the user last visited. If the user is new, it prints a generic welcome message. TIP: If you are calling a cookie on the same page you plan to set one, retrieve it before you overwrite it. How to Destroy a Cookie To destroy a cookie, use setcookie() again but set the expiration date to be in the past: ?php $past time() - 10; //this makes the time 10 seconds ago setcookie(UserVisit, date(F jS - g:i a), $past);? ​Optional Parameters In addition to value  and  expire, the setcookie() function supports several other optional parameters: Path​ identifies the server path of the cookie. If you set it to / then the cookie will be available to the entire domain. By default, the cookie works in the directory its set in, but you can force it to work in other directories by specifying them with this parameter. This function cascades, so all subdirectories within a specified directory will also have access to the cookie.Domain​  Ã¢â‚¬â€¹identifies the specific domain that the cookie works in. To make the cookie work on all subdomains, specify the top-level domain explicitly (e.g., sample.com). If you set the domain to www.sample.com then the cookie is only available in the www subdomain.Secure​ specifies whether the cookie should transmit over a secure connection. If this value is set to TRUE then the cookie will set only for HTTPS connections. The default value is FALSE.Httponly​, when set to TRUE, will only allow the cookie to be accessed by the HTTP protocol. By default, the value is FALSE. T he benefit of setting the cookie to TRUE is that scripting languages cannot access the cookie.

Monday, March 2, 2020

History of Swaziland in Africa

History of Swaziland in Africa Early Migrations: According to tradition, the people of the present Swazi nation migrated south before the 16th century to what is now Mozambique. Following a series of conflicts with people living in the area of modern Maputo, the Swazis settled in northern Zululand in about 1750. Unable to match the growing Zulu strength, the Swazis moved gradually northward in the 1800s and established themselves in the area of modern or present Swaziland. Claiming Territory: They consolidated their hold under several able leaders. The most important was Mswati II, from whom the Swazis derive their name. Under his leadership in the 1840s, the Swazis expanded their territory to the northwest and stabilized the southern frontier with the Zulus. Diplomacy with Great Britain: Contact with the British came early in Mswatis reign when he asked British authorities in South Africa for assistance against Zulu raids into Swaziland. It also was during Mswatis reign that the first whites settled in the country. Following Mswatis death, the Swazis reached agreements with British and South African authorities over a range of issues, including independence, claims on resources by Europeans, administrative authority, and security. South Africans administered Swazi interests from 1894 to 1902. In 1902 the British assumed control. Swaziland – A British Protectorate: In 1921, after more than 20 years of rule by Queen Regent Lobatsibeni, Sobhuza II became Ngwenyama (lion) or head of the Swazi nation. The same year, Swaziland established its first legislative body – an advisory council of elected European representatives mandated to advise the British high commissioner on non-Swazi affairs. In 1944, the high commissioner conceded that the council had no official status and recognized the paramount chief, or king, as the native authority for the territory to issue legally enforceable orders to the Swazis. Worries About Apartheid South Africa: In the early years of colonial rule, the British had expected that Swaziland would eventually be incorporated into South Africa. After World War II, however, South Africas intensification of racial discrimination induced the United Kingdom to prepare Swaziland for independence. Political activity intensified in the early 1960s. Several political parties were formed and jostled for independence and economic development. Preparing for Independence in Swaziland: The largely urban parties had few ties to the rural areas, where the majority of Swazis lived. The traditional Swazi leaders, including King Sobhuza II and his Inner Council, formed the Imbokodvo National Movement (INM), a group that capitalized on a close identification with the Swazi way of life. Responding to pressure for political change, the colonial government scheduled an election in mid-1964 for the first legislative council in which the Swazis would participate. In the election, the INM and four other parties, most having more radical platforms, competed in the election. The INM won all 24 elective seats. Constitutional Monarchy: Having solidified its political base, INM incorporated many demands of the more radical parties, especially that of immediate independence. In 1966 Britain agreed to discuss a new constitution. A constitutional committee agreed on a constitutional monarchy for Swaziland, with self-government to follow parliamentary elections in 1967. Swaziland became independent on 6 September 1968. Swazilands post-independence elections were held in May 1972. The INM received close to 75% of the vote. The Ngwane National Liberatory Congress (NNLC) received slightly more than 20% of the vote and three seats in parliament. Sobhuza Declares Absolute Monarchy: In response to the NNLCs showing, King Sobhuza repealed the 1968 constitution on April 12, 1973, and dissolved parliament. He assumed all powers of government and prohibited all political activities and trade unions from operating. He justified his actions as having removed alien and divisive political practices incompatible with the Swazi way of life. In January 1979, a new parliament was convened, chosen partly through indirect elections and partly through direct appointment by the King. An Autocratic Regent: King Sobhuza II died in August 1982, and Queen Regent Dzeliwe assumed the duties of the head of state. In 1984, an internal dispute led to the replacement of the Prime Minister and eventual replacement of Dzeliwe by a new Queen Regent Ntombi. Ntombis only child, Prince Makhosetive, was named the heir to the Swazi throne. Real power at this time was concentrated in the Liqoqo, a supreme traditional advisory body that claimed to give binding advice to the Queen Regent. In October 1985, Queen Regent Ntombi demonstrated her power by dismissing the leading figures of the Liqoqo. Call for Democracy: Prince Makhosetive returned from school in England to ascend to the throne and help end the continuing internal disputes. He was enthroned as Mswati III on April 25, 1986. Shortly afterward he abolished the Liqoqo. In November 1987, a new parliament was elected and a new cabinet appointed.In 1988 and 1989, an underground political party, the Peoples United Democratic Movement (PUDEMO) criticized the King and his government, calling for democratic reforms. In response to this political threat and to growing popular calls for greater accountability within government, the King and the Prime Minister initiated an ongoing national debate on the constitutional and political future of Swaziland. This debate produced a handful of political reforms, approved by the King, including direct and indirect voting, in the 1993 national elections.Although domestic groups and international observers criticized the government in late 2002 for interfering with the independence of the judiciary, parliame nt, and freedom of the press, significant improvements have been made concerning rule of law in the past two years. Swaziland’s Court of Appeals resumed hearing cases in late 2004 after a two-year absence in protest of the government’s refusal to abide by the court’s decisions in two important rulings. In addition, the new Constitution went into effect in early 2006, and the 1973 proclamation, which, among other measures, banned political parties, lapsed at that time.(Text from Public Domain material, US Department of State Background Notes.)