Pages: [1]   Go Down
Send this topic | Print
Author Topic: Couple Php questions  (Read 555 times)
mghq
I am a,
Loyal 110MB Member
*******
Online Online

Posts: 2109


Google and Verizon partnership FTW


WWW
« on: December 06, 2008, 12:56:49 PM »

Ok well i have this code:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Request Quote</title>
</head>
<body>
<h1>Request Quote</h1>
<?php
if(isset($_POST['submitted'])) {

if(!empty(
$_POST['name']) && !empty($_POST['email']) && !empty($_POST['requests'])) {

$body = "Name: {$_POST['name']}\n\nRequests: {$_POST['requests']};

$body = wordwrap($body, 70);

mail('megagamingh[ @ ] gmail.com'), 'Requests', $body, "
From: {$_POST['email']}");

echo '<p><em>Thank you for your request. I will reply with a quote soon.</em></p>';

$_POST = array();

} else {

echo '<p style="
font-weight: bold; color: #C00">Please completely fill out the form.</p>';
}

}

 
?>

 
 <p>Please fill out this form to request a quote from me.</p>
 
 <form action="request.php" method="post">
 <p>Name:<input type="text" name="name" size="30" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
 <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
 <p>Your Request:</p> <p><textarea name="requests" rows="10" cols="30"><?php if(isset($_POST['requests'])) echo $_POST['requests']; ?></textarea></p>
 <p><input type="submit" name="submit" value="Submit" /></p>
 <p><input type="hidden" name="submitted" value="TRUE" /></p>
 </form>
</body>
</html>
How can i make it also submit the users ip address so that if they spam i can ban them.
Also i would like to add something like what is 2+2= so that spambots wont be able to send anything.
« Last Edit: December 06, 2008, 01:18:12 PM by mghq » Logged

MGHQ Your Gaming Headquarters


New 110mb Status Monitor (Back online and 13x faster Smiley)
Hi! I’m a signature virus! Add me to your signature to help me spread.
Ðaz
Web Master & Coder for Life
Loyal 110MB Member
*******
Offline Offline

Posts: 3219

Gone with the wind.


WWW
« Reply #1 on: December 06, 2008, 03:15:00 PM »

Well, to make it email you their IP as well you can do:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Request Quote</title>
</head>
<body>
<h1>Request Quote</h1>
<?php
if(isset($_POST['submitted'])) {

if(!empty(
$_POST['name']) && !empty($_POST['email']) && !empty($_POST['requests'])) {

$body = "Name: {$_POST['name']}\n\nRequests: {$_POST['requests']}\n\nIP: {$_SERVER['REMOTE_ADDR']}";

$body = wordwrap($body, 70);

mail('megagamingh[ @ ] gmail.com'), 'Requests', $body, "From: {$_POST['email']}");

echo
'<p><em>Thank you for your request. I will reply with a quote soon.</em></p>';

$_POST = array();

} else {

echo
'<p style="font-weight: bold; color: #C00">Please completely fill out the form.</p>';
}

}

 
?>

 
 <p>Please fill out this form to request a quote from me.</p>
 
 <form action="request.php" method="post">
 <p>Name:<input type="text" name="name" size="30" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
 <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
 <p>Your Request:</p> <p><textarea name="requests" rows="10" cols="30"><?php if(isset($_POST['requests'])) echo $_POST['requests']; ?></textarea></p>
 <p><input type="submit" name="submit" value="Submit" /></p>
 <p><input type="hidden" name="submitted" value="TRUE" /></p>
 </form>
</body>
</html>
(You were also missing a quote on a $body = line.)
As for the 2+2 human checker, you're going to want to use php sessions or cookies.
Logged

Personal site: http://matt-shaffer.com
Currently being eaten alive by school and attempting to make a half decent game.

Adios. Contact info is in profile. Might want to email me any IM details first, or I won't add you.
robleyd
Official 110mb Guru
********
Online Online

Posts: 5700

Ask before you PM


« Reply #2 on: December 06, 2008, 03:29:57 PM »

Quote
As for the 2+2 human checker, you're going to want to use php sessions or cookies.

Huh? Just add another text field where the user can put an answer to the question you pose, and check that field before deciding to send the mail.
Logged

I once had a hard drive clunk-clicking
Strange noises, weird sounds and tick-ticking
I thought I would wait
And procrastinate...
But now all my data is missing
--------------
dd, a dump, a data dump
read a line from standard in
$USER, the name I call my self
make - a long long time to run
.so a library that is shared
.ko it's not the same as .so
tee, a redirect with in and out
and brings us back to dd d d d
idasfoto
Member
*
Offline Offline

Posts: 36


WWW
« Reply #3 on: December 06, 2008, 07:17:15 PM »

Well, you could use a image-generator.
Code:
<?php
function generate_image()
{
$image=imagecreate(64,24);
$background_color=imagecolorallocate($image,255,255,255);
for(
$i=0;$i<4;$i++)
{
$tmp_type=rand(0,2);
if(
$tmp_type==0)
{
$tmp_letter=chr(rand(65,90));
}
if(
$tmp_type==1)
{
$tmp_letter=chr(rand(97,122));
}
if(
$tmp_type==2)
{
$tmp_letter=rand(0,9);
}
$tmp_color=imagecolorallocate($image,rand(0,155),rand(0,155),rand(0,155));
imagestring($image,rand(4,5),$i*16+rand(0,4),rand(4,8),$tmp_letter,$tmp_color);
$code="$code$tmp_letter";
}
imagepng($image,"image.png");
imagedestroy($image);
return
$code;
}
?>
Take a look at that script that I wrote. $code will contain the code that is generated. Here's an example how it works:
Code:
<?php
$code
=generate_image();
echo
"<img src=\"image.png\"> = $code";
?>
« Last Edit: December 06, 2008, 07:21:57 PM by idasfoto » Logged
M0ZZA
A Man In A Trance...
Loyal 110MB Member
*******
Offline Offline

Posts: 2542


So yeah, I would like to be a moderator.


WWW
« Reply #4 on: December 06, 2008, 09:00:28 PM »

the math question would be pretty easy, just do this

HTML
Code:
what is 4+4
<input id="math" value="" />

PHP :

Code:
$math = $_POST['math'];
if($math != 8){
 die("Validation failed");
}

that would ask the same question, but you could do :

PHP page :
Code:
<?php
$_SESSION
['matha'] = rand(1,9);
$_SESSION['mathb'] = rand(1,9);

echo
'
<form action="sendmail.php" method="POST" />
what is :'
.$_SESSION['matha'].' + '.$_SESSION['mathb'].'<br />
<input id="math" value="" />
</form>'
;

and then in sendmail.php :
Code:
<?php
$mathAnswer
= $_SESSION['matha']+$_SESSION['mathb'];
$math = $_POST['math'];

if(
$math != $mathAnswer){
 die(
"Validation failed");
}
?>


I just wrote that blindly - so it may not work...
Logged

mghq
I am a,
Loyal 110MB Member
*******
Online Online

Posts: 2109


Google and Verizon partnership FTW


WWW
« Reply #5 on: December 06, 2008, 10:26:29 PM »

I get this error:
Quote
Parse error: syntax error, unexpected ',' in /home/mghqco/public_html/request.php on line 19

This is the line of code:
Code:
mail('megagamingh@gmail.com'), 'Requests', $body, "From: {$_POST['email']}");

What is wrong.
Logged

MGHQ Your Gaming Headquarters


New 110mb Status Monitor (Back online and 13x faster Smiley)
Hi! I’m a signature virus! Add me to your signature to help me spread.
Confuser
Creator of eoCMS
Loyal 110MB Member
*******
Offline Offline

Posts: 3128


The Forum's Angel


WWW
« Reply #6 on: December 06, 2008, 10:37:33 PM »

you have a ) after megagamingh[ @ ] gmail.com
Logged

mghq
I am a,
Loyal 110MB Member
*******
Online Online

Posts: 2109


Google and Verizon partnership FTW


WWW
« Reply #7 on: December 07, 2008, 12:00:10 AM »

Yeah i noticed that once i had posted.
Logged

MGHQ Your Gaming Headquarters


New 110mb Status Monitor (Back online and 13x faster Smiley)
Hi! I’m a signature virus! Add me to your signature to help me spread.
mghq
I am a,
Loyal 110MB Member
*******
Online Online

Posts: 2109


Google and Verizon partnership FTW


WWW
« Reply #8 on: January 12, 2009, 12:12:44 AM »

Well, to make it email you their IP as well you can do:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Request Quote</title>
</head>
<body>
<h1>Request Quote</h1>
<?php
if(isset($_POST['submitted'])) {

if(!empty(
$_POST['name']) && !empty($_POST['email']) && !empty($_POST['requests'])) {

$body = "Name: {$_POST['name']}\n\nRequests: {$_POST['requests']}\n\nIP: {$_SERVER['REMOTE_ADDR']}";

$body = wordwrap($body, 70);

mail('megagamingh[ @ ] gmail.com'), 'Requests', $body, "From: {$_POST['email']}");

echo
'<p><em>Thank you for your request. I will reply with a quote soon.</em></p>';

$_POST = array();

} else {

echo
'<p style="font-weight: bold; color: #C00">Please completely fill out the form.</p>';
}

}

 
?>

 
 <p>Please fill out this form to request a quote from me.</p>
 
 <form action="request.php" method="post">
 <p>Name:<input type="text" name="name" size="30" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>
 <p>Email Address: <input type="text" name="email" size="30" maxlength="80" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
 <p>Your Request:</p> <p><textarea name="requests" rows="10" cols="30"><?php if(isset($_POST['requests'])) echo $_POST['requests']; ?></textarea></p>
 <p><input type="submit" name="submit" value="Submit" /></p>
 <p><input type="hidden" name="submitted" value="TRUE" /></p>
 </form>
</body>
</html>
(You were also missing a quote on a $body = line.)
As for the 2+2 human checker, you're going to want to use php sessions or cookies.

Ok how would i add a dropdown that has to be required and a button select that has to be selected?
Logged

MGHQ Your Gaming Headquarters


New 110mb Status Monitor (Back online and 13x faster Smiley)
Hi! I’m a signature virus! Add me to your signature to help me spread.
Pages: [1]   Go Up
Send this topic | Print
Jump to: