Wikipedia:Reference desk/Archives/Computing/2016 May 2

Computing desk
< May 1 << Apr | May | Jun >> May 3 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


May 2 edit

EasyPHP Devserver edit

I downloaded and installed this, and it seems to be running OK, but it's not obvious to me how I actually use a PHP file and see the results. I tried creating a file with the PHP extension, but my PC (Windows 7) doesn't know what to do with it when I click on it. The links they provide for "Introduction" seem to just take me back to pages talking about how to download, install, and upgrade, not actually use it. Any ideas ? Does it have a development window I need to start somehow, then cut and paste code into it ? StuRat (talk) 02:39, 2 May 2016 (UTC)[reply]

It's a software bundle for running a local dev server. You run the server on a loopback interface and connect to it. If you don't know how to use it, you should probably look for a good book on Web development. --71.110.8.102 (talk) 02:52, 2 May 2016 (UTC)[reply]
It really shouldn't require reading a book to figure out what I need to click on to get a PHP program to run on a PHP server. StuRat (talk) 03:05, 2 May 2016 (UTC)[reply]
I assumed you were trying to do Web development, because that's generally why you'd download a dev server package. I'm smelling XY problem here. Let's step back. What are you trying to accomplish? If you have a command-line PHP program you just want to run locally, all you need is PHP, which you can download here. However, you need to be sure the program is intended to be run locally from a command line. If you're trying to run a local install of "Web software" like Mediawiki, you will need to set up the full server environment, because those programs are designed to interact with clients over an Internet connection. --71.110.8.102 (talk) 04:55, 2 May 2016 (UTC)[reply]
While PHP does have a command-line tool, it is commonly used as a web server scripting tool. It is likely that your problem is not with PHP. Your problem is in understanding how to use your web server. 209.149.115.199 (talk) 13:51, 2 May 2016 (UTC)[reply]

I want to get the following "Hello World" program to run:

<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>

<?php echo '

Hello World

'; ?>

 </body>
</html>

(Wiki seems to do something weird to the echo line, go into edit to see the unmolested version.) How can I do that ? I am helping somebody out who is taking a class in PHP, and the instructor said to download the EasyPHP Devserver and run it there. Presumably more challenging PHP programs will follow, but for now this is all that is needed. So, how do I get it to work ? StuRat (talk) 15:02, 2 May 2016 (UTC)[reply]

Run the EasyPHP server. That is a web server. It listens on port 80. If that is confusing, step back and study "What is a web server?" Now, put your PHP file in the server's document folder. Where is that? It should be somewhere in the EasyPHP install. Assume you called the file 'hello.php'. Open your web browser and go to localhost/hello.php. If EasyPHP is installed and EasyPHP is running and you put the file in the correct folder and the file doesn't have a typo... you will see the web page with Hello World in it. This is *not* a PHP problem. This is a "How do I install and use a web server?" problem. 209.149.115.199 (talk) 15:42, 2 May 2016 (UTC)[reply]
OK, Google Chrome seemed to recognize "localhost" when I typed it in the address bar. It took me to a page that says EasyPHP Devserver, so that's a good sign. It lists 3 folders there, all empty: my portable files, projects, and scripts. I went into "my portable files", and the address bar changed to "http://localhost/my%20portable%20files/". But here's where I hit a wall. I can't navigate there using the "My Computer" icon on the Desktop, and I can't find it using Start + search bar. So how do I place my hello.php there ? I tried dragging it into the folder in the Google Chrome window, but that didn't work.
I also found an option on the EasyPHP Devserver mini icon (down by the clock) labeled "Local Web", and that takes me to the same folders listed above (within Google Chrome), except the word "localhost" is replaced by "127.0.0.1". StuRat (talk) 04:40, 3 May 2016 (UTC)[reply]
One point - StuRat's file should be called "hello.htm" (or something similar), not "hello.php", as it's an HTML file. It may need some additional HTML headers to stop various elements of the system complaining. Tevildo (talk) 15:50, 2 May 2016 (UTC)[reply]
From a cursory scan of the EasyPHP docs, it uses the .php extension to identify a file as containing PHP. Naming it .htm indicates that it does not contain PHP and will not be parsed. It is possible to alter this behavior in the setup. From the question here, it is not possible to know if StuRat altered the default setup or not - or even if EasyPHP is running. 209.149.115.199 (talk) 15:53, 2 May 2016 (UTC)[reply]
It's definitely running (see above). The only modification I made was changing the name of the folder from "EasyPHP" to "PHPEasy", because I want to find it when looking for "PHP", not "Easy". StuRat (talk) 05:03, 3 May 2016 (UTC)[reply]
The reason you code appears weird here is because the <p> paragraph HTML element is a valid HTML element in wikimarkup. (I used the <p> element all the time rather than manually introducing new indented paragraphs although I just realised properly I should also add a closing </p>.) It is intepreted even when you start the sentence with a space indicating it should be displayed as code, as I think is most other valid wikitext which doesn't conflict (try for example a template or a link). To avoid the problem, you should <nowiki></nowiki> the <p> elements and any other elements that are valid in wikimarkup or do something else which will ensure the elements are not passed. Nil Einne (talk) 08:07, 3 May 2016 (UTC)[reply]
I tried <nowiki>, and it did this to it:

<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html>

Any other suggestions ? StuRat (talk) 16:08, 3 May 2016 (UTC)[reply]
Sorry I guess I wasn't as clear as I thought. You need to <nowiki></nowiki> only elements you do not want to be intepreted as wikimarkup. If you <nowiki></nowiki> anything which you do want to be intepreted as wikimarkup then these will also not be intepreted. This includes the spaces before lines to force them to be intepreted as code and also I guess any simple line breaks. Since I'm pretty sure only the <p></p> elements are being intepreted, one of the simplest method is probably:
 <html>
  <head>
   <title>PHP Test</title>
  </head>
  <body>
   <?php echo '<nowiki><p>Hello World</p></nowiki>'; ?> 
  </body>
 </html>
Note the above text is intended to be read on the intepreted version of this page as an example of what you want to do in source. In other words, you shouldn't need to view source to understand this comment. In fact you can copy the above text in intepreted form into source and as shown below, it will produce what I assume is your desired result:
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
  <?php echo '<p>Hello World</p>'; ?> 
 </body>
</html>
BTW I nowikied your nowiki above since I'm not sure if it could cause problems.

Nil Einne (talk) 05:58, 4 May 2016 (UTC)[reply]

I see. So either it can look good in edit mode or in read mode, but not in both ? StuRat (talk) 06:03, 4 May 2016 (UTC)[reply]
Not really sure the relevance of your observation. That applies to pretty much everything on wikipedia. The nature of any markup means you can either see the markup which helps you to understand what's going on and edit it but doesn't generally look so pretty. Or you can see the rendered view which shows you what was hopefully intended by the markup. (I'm pretty sure there are alternatives to nowiki which could be used which will obviously look and work different.) The same with indents, links, let alone tables etc. This of course also applies to the HTML markup you're trying to test on your PHP server or whatever. (I'm not denying some markup is simpler and more readable than other markup. And perhaps I should also mention some markup may be intepreted and replaced with other markup, e.g. signatures or substituted templates after saving.)

In case there's some confusion over my clarification above, the normal assumption is the code displayed in a guide is the code you want to use presuming the person writing the guide didn't screw up. The main exception would be if it's specifically presented as an example output and you should check the code to see what the input was to get the output. So I presented my code accordingly. However since there had already been confusion here along with discussions about viewing source, I wanted to make it clear that this was just a normal example where you should view the rendered text rather than the code. The clarification was otherwise irrelevant to my example.

In a similar fashion, if I tell someone to sign their posts with four tildes ~~~~, I don't generally expect them to sign their posts like this <nowiki>~~~~</nowiki> in code form to produce ~~~~ in displayed form. If they do, there's a slight chance they genuinely made a mistake, but more likely they're trolling. And yes, these examples are intended to be read in the rendered view.

Nil Einne (talk) 08:18, 4 May 2016 (UTC)[reply]

I am just partial to WYSIWYG. I would have preferred if putting a space in front alone was enough to disable wiki markup, or perhaps if a <wiki></wiki> pair was needed to enable wiki markup in the first place. StuRat (talk) 15:03, 4 May 2016 (UTC)[reply]

SQL Query for non-existent values edit

I appreciate if you can assist me with creating a SQL query for a specific situation I am facing, which I can best explain through an example.

Suppose I have this table, with people's favorite fruits:

Record No. FavoriteFruit
1 Apple
2 Apple
3 Banana
4 Banana
5 Orange

I want to be able to summarize this data; however I want to explicitly show that FavoriteFruit "Strawberry" has received zero responses.

In other words, I want the output of the query to look like this:

Favorite Fruit Count
Apple 2
Banana 2
Orange 1
Strawberry 0

Thank you, --Hia10 (talk) 07:09, 2 May 2016 (UTC)[reply]

I think you can still query for "Strawberry" if you like. The query would just show 0 rows matching. This also does depend exactly what you mean by your question. I assume you have some external list you want to check the table against, and that "Strawberry" is in that list.
216.173.144.188 (talk) 08:26, 2 May 2016 (UTC)[reply]
The issue I expect you've had is that if you use something like "select fruit, count(*) from fruits join favorites on fruits.fruit=favorites.fruit", then strawberry won't show up. If you use "left outer join", strawberry gets a count of 1 for the null row. A simple solution, use a subselect of "select fruit, count(*) cnt from favorites". Then "select fruit, nvl(cnt,0) cnt from fruits left outer join (select fruit, count(*) cnt from favorites)..." Then, strawberry will have a null value for cnt, you null-value it to zero. 209.149.115.199 (talk) 12:37, 2 May 2016 (UTC)[reply]
The issue I see is where exactly does the word "Strawberry" come from ? If it doesn't exist in any table, then SQL isn't going to find it unless you explicitly list it in your query. Using embedded SQL, I would do something like this:
SELECT COUNT(*) FROM FAVORITES WHERE FAVORITES.FRUIT = "Apple";
SELECT COUNT(*) FROM FAVORITES WHERE FAVORITES.FRUIT = "Banana";
SELECT COUNT(*) FROM FAVORITES WHERE FAVORITES.FRUIT = "Orange";
SELECT COUNT(*) FROM FAVORITES WHERE FAVORITES.FRUIT = "Strawberry";
Then I would format my own output based on those results. However, this list of potential fruit is then in the program, not the database, and that's not ideal. It would be better to have a 2nd table which lists all potential fruit types. This can be used for validation of the main table as well as the joined query. StuRat (talk)
I guess the selected fruit may change. The practical solution is a pivot table query, to do it with a single query. A record containing zero in Your query is beeing generated when Your query is based on a table or query containing or listing all selected fruit, first. This table or query is Your table sample Favorite Fruit. Favorite Fruit can be generated from suppliers, recipe ingredients list or orders. --Hans Haase (有问题吗) 19:44, 4 May 2016 (UTC)[reply]
SELECT "Orders"."Article", SUM( "Stock"."Qty" ) "Qty"
FROM { oj "Stock" RIGHT OUTER JOIN "Orders" ON "Stock"."Fruit" = "Orders"."Article" }
GROUP BY "Orders"."Article"
ORDER BY "Orders"."Article" ASC
In this sample, created with LibreOffice Base, the zero is returned as null. In can be subsistuted in furter use to enforce the zero be displayed. --Hans Haase (有问题吗) 20:10, 4 May 2016 (UTC)[reply]
Other syntax:
SELECT Orders.Article, SUM( Stock.Qty ) as Qty
FROM Stock RIGHT OUTER JOIN Orders ON Stock.Fruit = Orders.Article
GROUP BY Orders.Article
ORDER BY Orders.Article ASCENDING
--Hans Haase (有问题吗) 12:16, 5 May 2016 (UTC)[reply]

RSA key size for SSH edit

For SSH using RSA, do the RSA key sizes have to match exactly for the server side and the client side?

Or could the following situation work?

Server side public key 3072-bits

Client side private key 2048-bits

Johnson&Johnson&Son (talk) 08:45, 2 May 2016 (UTC)[reply]

The public and private key are a pair that come from the same number. The private key will have two numbers that multiply to give the public key. So you cannot vary the length like that. Graeme Bartlett (talk) 11:43, 2 May 2016 (UTC)[reply]
Just to beat this topic into the ground (and avoid paying attention in this meeting)... Public-Private keys are often used for handshaking. In that case, there is a server key pair and a client key pair. The server holds a private key and sends out a public key. The client holds a private key and sends out a public key. Using RSA, the key pairs are produced using two large prime numbers. The server's key pair uses two large prime numbers. The client's key pair uses a different set of two large prime numbers (technically, they could use the same prime numbers, but the chances of that are very very small). Because the public-private pair are produced at the same time, the public key and private key have the same number of bits. But, the server and client don't need to use the same number of bits. The server might produce a 2048-but public-private pair. The client produces a 1024-bit public-private pair. It still works. For a simple handshake, the client encrypts a message using its private key. It encrypts the result of that using the server's public key. The server gets it and decrypts it using its private key - the pair with the public key that was last used. Then, it decrypts the result with the client's public key - the pair with the private key that was used. At no point in that process was the server's key used to encrypt/decrypt the client's key. They are used independently of each other, but used on the same message. With this basic understanding, you can work on a DH key exchange in which both the client and server have public-private key pairs. You'll see that the same principle still holds. While the bit size of a pair is constant, the bit size of all key pairs used doesn't need to be constant. 209.149.115.199 (talk) 13:28, 2 May 2016 (UTC)[reply]

digital eletronics - Borrow Skip Subtractor edit

are there Borrow Skip Subtractor? if yes how it's done?-95.239.177.216 (talk) 14:07, 2 May 2016 (UTC)[reply]

Reverse subtract and skip if borrow?--178.103.251.111 (talk) 00:02, 3 May 2016 (UTC)[reply]
Found something: http://r.search.yahoo.com/_ylt=A7x9UnAO6ydXrncA9IV3Bwx.;_ylu=X3oDMTByMm4zYjFxBHNlYwNzcgRwb3MDNQRjb2xvA2lyMgR2dGlkAw--/RV=2/RE=1462262670/RO=10/RU=http%3a%2f%2fwww.retroprogramming.com%2f2009%2f01%2fultimate-risc-one-instruction-set.html/RK=0/RS=iYRCaDq.HjbksW_CfBXpLArtuZU- --178.103.251.111 (talk) 00:07, 3 May 2016 (UTC)[reply]
178.103.251.111, this link can not be retrieved by other users! --Hans Haase (有问题吗) 13:35, 3 May 2016 (UTC)[reply]
Ok try this. One instruction set computer--178.103.251.111 (talk) 17:13, 3 May 2016 (UTC)[reply]
No, I would the logic circuit (only HW) .--95.239.177.216 (talk) 10:52, 4 May 2016 (UTC)[reply]

How is adding bots to a website by a user possible? edit

This website talks about the process that he uses to find love on the Internet. It says that he adds bots to the website, and the server detects those as invalid bots. On other websites, I've heard that some people try to take advantage of the lack of security and send bots to automate the process of performing certain activities on the site. How does that work? Does a person just make a program that reads the HTML file and searches specific text and prompts the program to execute instructions that interact with the web browser? Is there a way for the computer to confirm the identity of a legitimate human user as opposed to a bot? 140.254.77.172 (talk) 17:28, 2 May 2016 (UTC)[reply]

Web communications use HTTP (primarily over IP). HTTP is just text. When you go to a web page in your web browser, it sends text to the web server. The web server sends text back. (If you want to be an ass about it, you can argue that the response will contain binary data if you specifically requested a binary file, such as a jpeg - but how does that help anyone understand what is going on?) So, I can write a program that sends the text request on port 80 (the web port) to a server. It doesn't know that my program sent the request. It just sees text. It responds. I can have my program read that text and, based on what it sees, send another request - again, just some text. I can automate a lot of processes by doing this. For example, I need to get a lot of census data at work. So, I wrote a program that sends requests to the census website and reads the responses to get the data that I need. That particular practice is commonly called screen scraping. Hopefully it is easy to see that since all you are doing is sending and receiving text, it is actually a rather easy program to write. 209.149.115.199 (talk) 17:36, 2 May 2016 (UTC)[reply]
See Internet bot. Here are some instruction on how to make one: [1]. And even easier, a semi-automatic bot maker application [2]. Here [3] is an interesting article that talks about how bots work in concept, and about how bots can be used for various nefarious purposes. SemanticMantis (talk) 19:03, 2 May 2016 (UTC)[reply]
Our article on CAPTCHA should answer your last question. Dbfirs 12:35, 3 May 2016 (UTC)[reply]