Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking Users HTML form input with PHP
    primarykey
    data
    text
    <p>I am creating a web application that takes in a user input (Scientific Paper DOI) and queries a database to display a graph. I've been trying to limit the connections made to the database since its on a remote server (private DMZ with web server) by checking the user input if it matches a correct DOI.. if it doesn't then no connection to the database will be made, I hope this will help speed up the application if there are many users at once making queries.</p> <p>Pseudo: All paper DOIs start with "10.1103/" because they are all physics papers. This part I have implemented correctly using substr. Next I want to check every character in the input to make sure it only consists of only these characters:</p> <ul> <li>Letter</li> <li>Number</li> <li>"/"</li> <li>"."</li> </ul> <p>Example DOIs:</p> <ul> <li>10.1103/RevModPhys.9.1</li> <li>10.1103/RevModPhys.76.1015</li> <li>10.1103/PhysRevLett.95.208304</li> </ul> <p>Here is my code:</p> <pre><code>function checkDOI($doi) { if (substr($doi, 0, 8) != "10.1103/") { echo "Invalid DOI"; return false; } for ($n = 0; $n &lt; strlen($doi)+1; $n++) { if ( !ctype_alnum($doi[n]) &amp;&amp; $doi[n] != "." &amp;&amp; $doi[n] != "/") { echo "Invalid DOI"; return false; } } echo "Valid DOI"; return true; } if(isset($_POST['submit'])) { $doi_input = $_POST['doi_input']; checkDOI($doi_input); } </code></pre> <p>I am working with PHP and javascript for the very first time, the pseudo is fairly simple but for some reason, there is something wrong with the 2nd if statement. Not sure if I can really do that. The Echos are just for tests.</p> <p>Do you think doing this check for every input will slow down the application significantly? Is it worth it to limit the amount of connections to mysql?</p> <p>The bottom of the code will be modified once I have this working to only query the database if checked returns true. </p> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload