LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > peonuser
User Name
Password

Notices



Rate this Entry

My first (well almost) php program.

Posted 07-04-2011 at 11:44 AM by peonuser
Updated 07-05-2011 at 12:48 AM by peonuser

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:
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>
oracle.php
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>
odata
Code:
yes
no
maybe
Posted in Uncategorized
Views 3909 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    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 04:56 PM by Web31337 Web31337 is offline
  2. Old Comment
    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 11:14 PM by peonuser peonuser is offline
 

  



All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement

Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration