diplay a random number into html page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AluminX
Forum Newbie
Posts: 19
Joined: Sat Jul 17, 2004 9:53 am

diplay a random number into html page

Post by AluminX »

The Ninja Space Goat | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi
i have the following into a html page
[syntax="html"]<form action="process.php" method="post">
<table>
<tr><td>
Name:<br />
<input type="text" name="userName" id="userName" size="20"></input><br />
Comment:<br />
<textarea rows="10" cols="20" name="body"></textarea><br />
<input type="submit" name="submit" id="submit" value="Submit"></input>
<input type="reset" name="reset" id="reset" value="Reset"></input>
</td></tr>
</table>
</form>
untill here everything works fine but the problem is that some ppl just fload the page with spam(bots) and i would like to
make an array that contains numbers from 0 to 9 and randomly pick 2 numbers and display them between <textarea> and the buttons, something like "what is $firstRndNum + $secondRndNum equal to?<br /><input type="text" name="usersAns" id="usersAns"></input>
than when submit is clicked presses.php will take everything in(Name, body,$firstRndNum + $secondRndNum and usersAns)
and check if usersAns is == to $firstRndNum + $secondRndNum.
i have no clue how to implement this in html.
any ideas?

ps: i realise that this isn't going to stop the spam but i'm trying to learn how to work with php<->html


The Ninja Space Goat | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

This article on shiflett.org explains CSRF and how to defeat it (slow it down?) with a token in a form, just as you're describing.

You'll need to use some PHP on the form page.
AluminX
Forum Newbie
Posts: 19
Joined: Sat Jul 17, 2004 9:53 am

Post by AluminX »

cool i got that out of the way thanks for the help, now i got acouple of questions.
-how can i pass a variable from php page to another without using forms?
-how can i call a funtion located to a different php page from the current one?
thanks
Wade
Forum Commoner
Posts: 41
Joined: Mon Dec 18, 2006 10:21 am
Location: Calgary, AB, Canada

Post by Wade »

-how can i pass a variable from php page to another without using forms?
Try using PHP sessions...
http://www.phptutorial.info/learn/session.php
http://www.htmlgoodies.com/beyond/php/a ... hp/3472581

-how can i call a funtion located to a different php page from the current one?
If you have the function located in a php file like functions.php or something like that, then you can either

Code: Select all

include('functions.php');
or

Code: Select all

require('functions.php');
http://builder.com.com/5100-31-5077715.html
http://www.w3schools.com/php/php_includes.asp

Hope this helps...
AluminX
Forum Newbie
Posts: 19
Joined: Sat Jul 17, 2004 9:53 am

Post by AluminX »

ahh thanks alot :)
Post Reply