My first (well almost) php program.
Just a quick piece of code I wrote to start learning php. Had to do something better than "Hello, World" My odata file is quite a bit larger, but I just put the small version for sake of space. This program is beginner level, but it worked for me.
oracle.html:
oracle.php
odata
oracle.html:
Code:
<html> <body> <center><h1>The Oracle</h1> <hr> <form method="post" action="oracle.php"> Enter your question of the future to the oracle: <br> <br> <input type="text" name="message" /> <input type="submit" /> </form> <br> <br> When you press submit, this page will disappear. Then after cogitating, the Oracle will give you the answer. </center> <hr> </body> </form>
Code:
<html> <body> <center><h1> The Oracle</h1></center> <hr> Your question was: <br> <center> <?php echo $_POST["message"]; ?> </center> <br> Your answer is: <br> <br> <center> <?PHP $lines = file('odata'); // Loop through our array. foreach ($lines as $line) { } // show result echo $lines[rand(1,3)] . "<br />"; ?> </center> <hr> </body> <html>
Code:
yes no maybe
Total Comments 2
Comments
-
yeah, but it uses htmlspecialchars() in the wrong place, which will cause you problems in the future. your code is vulnerable to XSS, you don't take client's data to output just like that. rule number one: allow only valid input. be sure never to write any code that will be placed on public web servers before you read and understand AT LEAST this: http://www.linuxquestions.org/linux/...ng_secure_code . that article does NOT cover ALL the topics, I wrote it to explain some theory and basics.
Posted 07-04-2011 at 03:56 PM by Web31337 -
Thank you for your comment. I will probably update it at some time with your concerns as part of it. Right now the server the code runs on is not accessible by the real world. I have to crawl before I can walk so to speak in learning php programming. I will definitely consider your page and other ones like it such as http://php.robm.me.uk/.
Posted 07-04-2011 at 10:14 PM by peonuser