School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / php101 Refresh the current page Week #7 ADVANCED To-Do Assignment
 

 (#13 2003-08-07 16:46:54) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

TO-DO ASSIGNMENT: Go back to your advanced "send a url to a friend" mail script from course # 6 and add security so that only direct links from your domain and adultnetsurprise (so that we can check it out from the forum without the error popping up) can access the form and provide an error routine for those that try to come in from bookmark or type-in or illegal domain.
Post this assignment here so that we can offer comment/critique for you, but also post a URL to the working copy of the script and the complete source code of the script in your post.

scriptname.php <-- script name

Good luck to you!

 

 (#81 2003-08-22 07:17:01) Post Reply

Sk8rRIMuk
Need To Set


Enrolled: Aug 2003
Posts: 39
AP: 1

:) a nice script which I shall use to stop offsite linkings to my downlaods.

The working script URL is: http://www.katikai.com/ee/assi...rlemailform.php

*Sk8rRIMuk crosses fingers that link from forums works

As usual all my scripts can be found at:
http://www.katikai.com/ee/assignment

Heres the code for the page:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Week #7 Advanced To-Do Assignment</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<table width="750" border="1" cellspacing="1" cellpadding="1" align="center">
<tr>
<td align="left" valign="top" width="750" height="500">
<?php
//Check to see if they came from my site or forums
if($HTTP_REFERER=="http://www.katikai.com/ee/assignment/Week%20%237%20Advanced%20To-Do%20Assignment/"OR$HTTP_REFERER=="http://class.scriptschool.com/forums/php101/view/13/")
//If they did come from the site or forums go ahead and display code
{
//Check to see if the hidden value has been set yet if so execute the script
if($action=="send_mail"){
//Verify the e-mails are in the correct format
if(ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive0)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive1)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$receive2)){
if(
ereg("([[:alnum:].-]+)(@[[:alnum:].-]+.+)",$email)){
//Set the array for the email address and count the variables
$recipients=array("$receive0","$receive1","$receive2");
$sizeof=count($recipients);
//Set how the subject and other details will look in the email
$subject="$topic";
$body_of_email="
Thise-mailwassentby$name,
Who'semailis:$email,
$namewouldliketosharethefollowingwebsiteswithyou:
$url0$url1$url2
$namealsoleftthiscomment:
$comment"
;
$additional_headers="From:$emailn";
//Set the for()
for($i=0;$i<$sizeof;$i++){
//Check to see if the form has been submitted correct and print the message if not print the error
if(mail($recipients[$i],$subject,$body_of_email,$additional_headers)){
print(
"<p align="center">Yourmailwassuccessfullysentto: <b>$recipients[$i]</b></p>");
}else{
print(
"<p align="center">Oops! something didn't work right above, check the syntax of your code.</p>");
}}
//If the email address is not valid display these error messgaes
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$email</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive2</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive1</b>isnotinthecorrectformat</p>");
}
}else{
print(
"<p align="center">Oops!Itappearsthatyouremail: <b>$receive0</b>isnotinthecorrectformat</p>");
}
//If the hidden input hasnt been set ignore all that code and print the form
}else{
?>
<h3>Fill out the form below to send your three chossen website URL's to your three chossen freinds.</h3>
<form method="post" action="<?$PHP_SELF?>">
<input type="hidden" name="action" value="send_mail" />
Name: <input type="text" name="name" /><br />
Subject: <input type="text" name="topic" size="40" /><br />
Your Email: <input type="text" name="email" size="40" /><br />
Recipient One's Email: <input type="text" name="receive0" size="40" /><br />
Recipient Two's Email: <input type="text" name="receive1" size="40" /><br />
Recipient Three's Email: <input type="text" name="receive2" size="40" /><br />
URL One: <input type="text" name="url0" /><br />
URL Two: <input type="text" name="url1" /><br />
URL Three: <input type="text" name="url2" /><br />
Comments: <br /><textarea name="comment" cols="20" rows="10"></textarea><br />
<input type="submit" value="Submit" /><input type="reset" value="Reset" />
</form>
<?php
//End the php code for checking that the form was submitted
}
//If they didn't come from the site or forums display error
}else{print("<center>You are trying to enter this page via a bookmark, typein or illegal domain please go to the orignal page link (provided below), we only allow
direct links to this page for <b>Security Reasons</b>.<br /><a
href="
http://www.katikai.com/ee/assignment/">Click this and follow the correct
linktothispage</a>.<br/><i>Thankyouandsorryforanyinconveniecethismay
ofcaused
</i></center>");}
?>
</td>
</tr>
</table>
</body>
</html>



 

 (#184 2003-09-11 04:16:42) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

mah code, and again, im not sure if the mail function works properly, i couldnt test it yet, so if it doesnt, dont blame me on this forum but on week 6 basic and advanced forum please :)


<?
$mydomain
= "http://quicksaver.coolfreepage.com/";
$otherdomain = "http://class.scriptschool.com/forums/php101/view/13/";

if(
$HTTP_REFERER != $mydomain || $HTTP_REFERER != $otherdomain) {
print(
"Please access this page only through a link on quicksaver.coolfreepage.com or adultnetsurprise.com's forums, no exterior links are allowed.");
exit(); }

if(
$sent == "true") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to1) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to2) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to3)) {
$additional_headers = "From: $from\n";
$recipient = array("$to1\n, $to2\n, $to3\n");
$subject = "$name sent you his favourite urls!";
$body_of_email = "Message from $name:<br>$message<br><br>Urls sent:<br>$url1<br>$url2<br>url3<br>";
$addresses = count($recipient);
for(
$e=0; $e<$addresses; $e++) {
if (
mail($recipient[$e], $subject, $body_of_email, $additional_headers)) {
print(
"Email successfully sent!");
exit(); } else { print(
"<font color=\"ff0000\"><b>Error</b>: please make sure you fill in correctly all the fields in the form.</font>"); } } } else {
print(
"<font color=\"ff0000\"><b>Error</b>: please fill in correctly all three email addresses asked.</font>"); } }
?>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="sent" value="true">
Send your three favourite sites to your three best friends, just fill in all the fields.<br><br>
Your name: <input type="text" name="name" size="20"><br>
Your email: <input type="text" name="from" size="50"><br>
Friend: <input type="text" name="to1" size="50"><br>
Friend: <input type="text" name="to2" size="50"><br>
Friend: <input type="text" name="to3" size="50"><br>
Favourtie Url: <input type="text" name="url1" size"100"><br>
Favourtie Url: <input type="text" name="url2" size"100"><br>
Favourtie Url: <input type="text" name="url3" size"100"><br>
Aditional message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" value="send"><input type="reset" value="reset">
</form>


working url



 

 (#185 2003-09-11 04:20:34) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

wait, there's a glitch:


if($HTTP_REFERER != $mydomain && $HTTP_REFERER != $otherdomain) {
print("Please access this page only through a link on quicksaver.coolfreepage.com or adultnetsurprise.com's forums, no exterior links are allowed.");
exit(); }


thats the part i changed (lines 5, 6 and 7, the rest remains as well a the url

 

 (#239 2003-09-18 03:40:27) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

Here is My Week#7 Advanced Assignment
HTML http://members.lycos.co.uk/jef...an/class07a.htm
PHP File to Send mail http://members.lycos.co.uk/jef...an/class07a.php

Unauthorized URL Referer http://jeffkwan.150m.com




<html>
<head><title>Start of the HTML </title></head>
<?
$allowserver1
="members.lycos.co.uk";
$allowserver2="class.scriptschool.com";
$allowserver3="localhost";

if(!
$_SERVER['HTTP_REFERER'])
{
echo (
"U ARE NOT ALLOWED TO SEND MAIL THRU BOOKMARK OR DIRECT TYPE IN THE LINK. </br>");
echo (
"Click <a href='class07a.htm'>HERE</a> to LOGIN. <br>");
exit();
}
if(!
eregi($allowserver1,$_SERVER['HTTP_REFERER']) //Return true if not allowed
and !eregi($allowserver2,$_SERVER['HTTP_REFERER']) //Return true if not allowed
and !eregi($allowserver3,$_SERVER['HTTP_REFERER'])) //Return true if not allowed
{
echo (
"U ARE NOT ALLOWED TO SEND MAIL FROM UNAUTHORIZED WEBSITE REFERER. </br>");
echo (
"Click <a href='class07a.htm'>HERE</a> to LOGIN. <br>");
exit();
}

$actionmail=$_REQUEST['actionform'];
$name=$_REQUEST['name'];
$frommail=$_REQUEST['frommail'];
$tomail1=$_REQUEST['tomail1'];
$tomail2=$_REQUEST['tomail2'];
$tomail3=$_REQUEST['tomail3'];
$url1=$_REQUEST['url1'];
$url2=$_REQUEST['url2'];
$url3=$_REQUEST['url3'];

$subheader=$_REQUEST['subheader'];
$mailbody=$_REQUEST['mailbody'];

if(
$actionmail == "sendmail")
{
$frommail="From:".$frommail;
$mailbody="This email is send from Class 06 Advanced Assignemnt Program
"
.$name." Bring to you following exciting links
"
.$url1."
"
.$url2."
"
.$url3."
Comments by him
"
.$mailbody;
if(
ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail1) && ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail2) && ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $tomail3))
{
if(
ereg('([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)', $frommail))
{
$tomail=$tomail1.",".$tomail2.",".$tomail3;
if(
mail($tomail,$subheader,$mailbody, $frommail))
{
echo(
"<br>mail successfully sent to $recipient.<br>");
echo(
$tomail."<br>");
} else
{
echo(
"<br>Oobs! something didn't work right above, error on $tomail <br>");
}
} else
{
echo(
"<br>Mail Address may be incorrect!!! Please Check it!!");
}
} else
{
echo(
"<br>Mail Address may be incorrect!!! Please Check it!!");
}
} else
{
}

print(
" <form method='POST' action= ".$_SERVER['PHP_SELF']." >");
print(
" <input type='hidden' name='actionform' value='sendmail' >");
print(
" <b>Name:</b><br> ");
print(
" <input type='text' name='name' size='50' value=''><br>");
print(
" <b>Your Email:</b><br>");
print(
" <input type='text' name='frommail' size='50' value=''><br>");
print(
" <b>Your Friend's Email 1:</b><br>");
print(
" <input type='text' name='tomail1' size='50' value=''><br>");
print(
" <b>Your Friend's Email 2:</b><br>");
print(
" <input type='text' name='tomail2' size='50' value=''><br>");
print(
" <b>Your Friend's Email 3:</b><br>");
print(
" <input type='text' name='tomail3' size='50' value=''><br>");
print(
" <b>Your Favorite URL 1:</b><br>");
print(
" <input type='text' name='url1' size='50' value=''><br>");
print(
" <b>Your Favorite URL 2:</b><br>");
print(
" <input type='text' name='url2' size='50' value=''><br>");
print(
" <b>Your Favorite URL 3:</b><br>");
print(
" <input type='text' name='url3' size='50' value=''><br>");
print(
" <b>Subject:</b><br>");
print(
" <input type='text' name='subheader' size='50' value='Hello, my friends, I brought U new URLs'><br>");
print(
" <br><b>Comments:</b><br>");
print(
" <textarea name='mailbody' cols='39' rows='10'></textarea><br>");
print(
" <input type='submit' value='Submit'>");
print(
"</form>");

?>
</html>


 

 (#240 2003-09-18 03:44:43) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

However, I have one security question. I can enter the send mail pages by pressing refresh rather than enter it thru the html files. What can I do to modify the code to improve the security?


 

 (#241 2003-09-18 05:14:50) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

i dont have any advice for that, but if there is one i really think a very few people know it, because if you fill in a form, and then you click refresh at the result page, its like if youu filled it up again exactly, so for example, if you send some email to smeone, and you click refresh at the "email sent" page the email is sent again, and if you refresh again it's sent again, and again and again... i really never seen any script with that type of protection, there probably is some function to delete the values inserted from the memory, im also curious about this :)

 

 (#244 2003-09-18 05:50:13) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

so can I have any methods to erase the "hidden" value for that code?

Thx a lot

 

 (#254 2003-09-19 21:59:05) Post Reply

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

Use a header to redirect to an seperate 'script only' page to handle your mail() functions, then no browser back button can use it.


Look for an example of this from me soon...

logspirit

 

 (#263 2003-09-22 05:35:13) Post Reply

Quicksaver
Need To Set


Enrolled: Sep 2003
Posts: 90
AP: 1

logspirit, you got a point there but there's still the refresh button :P

anyway, here's my code, i had to change it due to some bug on week6advanced task


<?
global $PHP_self;
$mydomain = "http://quicksaver.coolfreepage.com/";
$otherdomain = "http://class.scriptschool.com/forums/php101/view/13/";
$me = "localhost";

if(
eregi("$mydomain",$HTTP_REFERER) || eregi("$otherdomain", $HTTP_REFERER) || eregi("$me", $HTTP_REFERER)) {

if(
$sent == "true") {
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $from) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to1) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to2) && ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $to3)) {
$additional_headers = "From: $from\n";
$recipient = array("$to1\n, $to2\n, $to3\n");
$subject = "$name sent you his favourite urls!";
$body_of_email = "Message from $name:
$message

Urls sent:
$url1
$url2
$url3
"
;
$addresses = count($recipient);

for(
$e = 0; $e < $addresses; $e++) {
if (
mail($recipient[$e], $subject, $body_of_email, $additional_headers)) {
print(
"Email successfully sent to $recipient[$e]!<br>");
} else { print(
"<font color=\"ff0000\"><b>Error</b> sending email to $recipient[$e].</font>"); } } } else {
print(
"<font color=\"ff0000\"><b>Error</b>: please fill in correctly all three email addresses asked.</font>"); }
exit(); }

} else {
print(
"Please access this page only through a link on quicksaver.coolfreepage.com or adultnetsurprise.com's forums, no exterior links are allowed.");
exit(); }
?>

<form method="post" action="<? $PHP_SELF ?>">
<input type="hidden" name="sent" value="true">
Send your three favourite sites to your three best friends, just fill in all the fields.<br><br>
Your name: <input type="text" name="name" size="20"><br>
Your email: <input type="text" name="from" size="50"><br>
Friend: <input type="text" name="to1" size="50"><br>
Friend: <input type="text" name="to2" size="50"><br>
Friend: <input type="text" name="to3" size="50"><br>
Favourtie Url: <input type="text" name="url1" size"100"><br>
Favourtie Url: <input type="text" name="url2" size"100"><br>
Favourtie Url: <input type="text" name="url3" size"100"><br>
Aditional message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" value="send"><input type="reset" value="reset">
</form>


not entirely working url - reminder, the online server i use doesnt support the mail() function

 

 (#359 2003-11-04 07:05:34) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

Here is only what i have changed in week6 assignment. was a little confusing work just because week6 had many if, else :) but anyway. working ENTER url:
http://tts.lt/~sir/scripts/week7adv.php



<?

<?

//set eregi. you can acess only from my enter page, adultnetsurprise and scriptschool...

if(eregi("http://tts.lt/~sir/scripts/week7adv.php|.+adultnetsurprise.+|$PHP_SELF|.+scriptschool.+", $HTTP_REFERER))

{

// Here goes week 6 code...

}

/* If you came not from my domain orscriptschool or adultnetsurprise: */

else
{

print(
"<center>You can't see this because you came from ");

if(!
$HTTP_REFERER)
{print (
"bookmark or just typed in browser this adress. <br><br> To access this script go to the <a href=week7adv.php>enter page</a>"); }
else { print(
"$HTTP_REFERER. <br><br>To access this script go to the <a href=week7adv.php>enter page</a>"); }

exit;
}




 

 (#360 2003-11-04 07:06:45) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

oh i forgot.:

main script:
http://tts.lt/~sir/scripts/week6adv.php

 

 (#361 2003-11-04 07:09:01) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

if you press link from here, it dont work... in eregi i wrote .+scriptschool.+

whats wrong there ?

 

 (#362 2003-11-04 07:10:42) Post Reply

Dest
Need To Set


Enrolled: Oct 2003
Posts: 18
AP: 1

oh it should be .+(scriptschool).+

sorry for that. now it works :D

 

 (#626 2004-06-08 16:19:42) Post Reply

Ahkorahil
Need To Set


Enrolled: Oct 2003
Posts: 20
AP: 1

Here goes my homework after a long time...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>6th (advanced) assignment in pHp</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$domain_1 = "http://members.lycos.co.uk/rain086/php/";
$domain_2 = "http://class.scriptschool.com/forums/php101/view/13/";
if($domain_1 OR $domain_2) {
if($action == "send_mail") {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f1)) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f2)) {
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $f3)) {
$get = array($f1, $f2, $f3);
$size = count($get);
$subject = "Url's";
$header = "oneman@hot.ee";
$body_of = "I send to You some links to watch:\n <a href =\"$u1\">url 1</a>\n <a href =\"$u2\">url 2</a> \n <a href =\"$u3\">url 3</a>";
for($a = 0; $a < $size; $a++) {
if(mail($saaja[$a], $subject, $body_of, $header)) {
print("Mail sent");
} else {
print("recipient has been written wrong"); }
} /// suleb FOR
} else {
print("freind3 is wrong"); }
} else {
print("freind2 is wrong"); }
} else {
print("freind 1 is wrong"); }
}else {
?>
<form method = "post" action = "<?php $PHP_SELF ?>">
<input type = "hidden" name= "action" value = "send_mail" />
To freind #1: <input type = "text" name="f1" value ="" size ="20" /><br />
To freind #2: <input type = "text" name = "f2" value = "" size = "20" /><br />
To freind #3: <input type = "text" name = "f3" value = "" size = "20" /><br />
URL #1: <input type = "text" name = "u1" value = "" size = "20" /><br />
URL #2: <input type = "text" name = "u2" value = "" size = "20" /><br />
URL #3: <input type = "text" name = "u3" value = "" size = "20" /><br />
<input type = "submit" value = "SEND" />
</form>
<?php }
} else {
print("Sorry, You are not allowed to fill this form");
}
?>
</body>
</html>

 

 (#784 2005-03-06 11:02:39) Post Reply

zman
Need To Set


Enrolled: Feb 2005
Posts: 15
AP: 1

My Advanced Assignment #7:



<html>
<head>
<title>ScriptSchool.com Assignment 7 (Advanced)</title>
</head>
<body bgcolor="666666">

<?php
/* ScriptSchool.com Assignment 7 (advanced)
// Go back to your advanced "send a url to a friend" mail script
// from course # 6 and add security so that only direct links from
// your domain and adultnetsurprise (so that we can check it out
// from the forum without the error popping up) can access the form
// and provide an error routine for those that try to come in from
// bookmark or type-in or illegal domain.*/
print("<center><p><b>ScriptSchool.com Assignment 7 (advanced)</b><br />
Go back to your advanced \"send a url to a friend\" mail script<br />
from course # 6 and add security so that only direct links from<br />
your domain and adultnetsurprise (so that we can check it out<br />
from the forum without the error popping up) can access the form<br />
and provide an error routine for those that try to come in from<br />
bookmark or type-in or illegal domain.</p></center>"
);

// check to see if the send_mail action is being sent. If not, then that means
// we haven't displayed the form yet, so let's do so.

$mydomain = "((^http://)(www\.)?(garagechoppers\.com/).+)";
$othervaliddomain = "((^http://)(www\.)?(adultnetsurprise\.com/).+)";

if(
eregi("$mydomain", $HTTP_REFERER) OR eregi("$othervaliddomain", $HTTP_REFERER))
{
// this visitor has come from a valid domain, so present the form
if($action == "send_mail")
{
// assign variables, and create an array of recipients called $to. $body
// formats the contents of the form in a readable manner in the end message.
$to = array($recipient1,$recipient2,$recipient3);
$from = $email;
$additional_headers = "From: $email\n";
$subject = "Some recommended websites from $name";
$body = "
This is the contents of the email from $name,
whose email address is $email.
$name has recommended the following websites...

$url1:
$url1comments

$url2:
$url2comments

$url3:
$url3comments

$addlcomments "
;

// check that the $from email address is valid. If not, display an error
// message to tel the user to go back and try again, and bail out.
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\-]+\.+)", $from))
{
// start a while loop to process the recipient addresses one by one
$a=0; // assign the starting index value
while($a<3)
{
// first, let's see if there is anything in the address field at all.
// If not, just skip it and try the next one (just in case).
if($to != '')
{
// we now know there is something there, so let's see if it is a
// valid email address before we proceed further. If it is not valid
// then skip it over, and display a message to that effect.
$recipient = $to[$a];
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\-]+\.+)", $recipient))
{
// ok, it appears to be a valid email address, let's send to it.
// If that fails, through a nice vague message about the server. <grin>
if(mail($recipient,$subject,$body,$additional_headers))
{
print(
"<center>mail successfully sent to $recipient</center>");
}
else
{
print(
"<center>Oops! Failed to send message to $recipient. This may be caused by a server problem.</center>");
}
}
else
{
print(
"<center>Sorry, but the recipient email address, $recipient, did not appear to be legitimate. - <b>Address skipped</b></center>");
}
}
$a++;
}
}
else
{
print(
"<center>Sorry, but your provided email address, $from, does not appear to be legitimate.<br /><b>Please page back, make any corrections, and try again.</b></center>");
}
}
else
{
?>
<center><form METHOD=POST action="<? $PHP_SELF ?>">
<input type="hidden" name="action" value="send_mail">
Share your favorite URLs with some friends<br />
Please enter your name, your email address, and the email addresses of up<br />
to three friends, and up to three of your most recommended websites and<br />
a couple words telling why you are recommending each.<br />
Finally, you can add a general comment, if you like.<br /><br />
<b>Note that the fields have been pre-filled for test purposes.<br />
To test for correct function, mangle up an email addy and see what happens.<b><br /><br />
Your Name: <input type="text" name="name" size=20 value="Eric">
Your Email: <input type="text" name="email" size=20 value="eric@pruss.net"><br />
First recipient email: <input type="text" name="recipient1" size=40 value="test1@garagechoppers.com"><br />
Second recipient email: <input type="text" name="recipient2" size=40 value="test2@garagechoppers.com"><br />
Third recipient email: <input type="text" name="recipient3" size=40 value="test3@garagechoppers.com"><br />
Please recommend three websites.
First Website: <input type="text" name="url1" size=40 value="http://garagechoppers.com"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url1comments">All you need to know to build the coolest choppers!</textarea><br /><br />
Second Website: <input type="text" name="url2" size=40 value="http://bloggingpoet.com"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url2comments">More than just poetry!</textarea><br /><br />
Third Website: <input type="text" name="url3" size=40 value="http://rumblebee.org"><br />
Why are you recommending this site?:<br /><textarea rows="2" cols="40" name="url3comments">All about the Rumble Bee!</textarea><br /><br />
Any additional comments:<br /><textarea rows="2" cols="40" name="addlcomments">I think these sites are cool, and hope that you will enjoy them!</textarea><br />
<input type="submit" value="Submit"></form>
<? }

}
else
{
// this visitor has NOT come from a valid domain, so print an error message
print("<center>Sorry, you are not a valid visitor.</center>");
}


?>


</body>
</html>


 

 (#834 2005-06-13 09:58:51) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

My week 7 advanced assignment:


<?
if($HTTP_REFERER=="")
{echo"ACCES DENIED";}
elseif(($HTTP_REFERER=="http://www.vegyta.3x.ro")or($HTTP_REFERER=="http://www.adultnetsurprise.com"))
{
$recipients=array($_POST["email_1"],$_POST["email_2"],$_POST["email_3"]);
$url=array($_POST["body_of_email_1"],$_POST["body_of_email_2"],$_POST["body_of_email_3"]);
$c1=count($recipients);

$body=$_POST["body_of_email"];
$e=$_POST["from"];
$headers="FROM:$e r\n";
$size=count($recipients);

for($i=0;$i<$c1;$i++){
$mas=$recipients[$i]; $bod=$url[$i];
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$mas))
{
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$_POST["from"])) {
if(mail($mas,"subiect",$bod,$headers))
{print("mail(s) successfully sent to e-mail adress specified"); }
else { print("error,your mail has not been sent");}
} //close from
else{echo"your from is invalid";}
} //close mail
else{print("oops it appears like your mail(s):is not in the correct format");}
}

?>


<br><br><br><br>
<form method="POST" action="end.php">
url1<input type="text"name="body_of_email_1"><br>
e-mail1<input type="text"name="email_1"> <br>
url2<input type="text"name="body_of_email_2"> <br>
e-mail2<input type="text"name="email_2"><br>
url3<input <input type="text"name="body_of_email_3"><br>
e-mail3<input type="text"name="email_3"> <br>
from<input type="text"name="from"><br>
<input type="submit"> <?}?>


 

 (#835 2005-06-14 05:22:01) Post Reply

vegyta2004
Need To Set


Enrolled: Apr 2005
Posts: 34
AP: 1

My last corrections on this assignment(i'll post the script whit the corrections):



<?
if(($HTTP_REFERER=="http://www.vegyta.3x.ro/")or($HTTP_REFERER=="http://www.vegyta.3x.ro/week7_avanced.php"))
{

?>
<br><br><br><br>
<form method="POST" action="<?PHP_SELF?>">
url1<input type="text"name="body_of_email_1"><br>
e-mail1<input type="text"name="email_1"> <br>
url2<input type="text"name="body_of_email_2"> <br>
e-mail2<input type="text"name="email_2"><br>
url3<input <input type="text"name="body_of_email_3"><br>
e-mail3<input type="text"name="email_3"> <br>
from<input type="text"name="from"><br>
<input type="submit">
<?


$recipients=array($_POST["email_1"],$_POST["email_2"],$_POST["email_3"]);
$url=array($_POST["body_of_email_1"],$_POST["body_of_email_2"],$_POST["body_of_email_3"]);
$c1=count($recipients);

$body=$_POST["body_of_email"];
$e=$_POST["from"];
$headers="FROM:$e r\n";
$size=count($recipients);

for($i=0;$i<$c1;$i++){
$mas=$recipients[$i]; $bod=$url[$i];
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$mas))
{
if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)",$_POST["from"])) {
if(mail($mas,"subiect",$bod,$headers))
{print("mail(s) successfully sent to e-mail adress specified"); }
else { print("error,your mail has not been sent");}
} //close from
else{echo"your from is invalid";}
} //close mail
else{print("oops it appears like your mail(s):is not in the correct format");}
}
} else

{echo"ACCES DENIED";echo"<br>","$HTTP_REFERER";}
?>





 

 (#973 2006-03-20 23:28:57) Post Reply

Russell
Need To Set


Enrolled: Mar 2006
Posts: 19
AP: 1

thanks zman for the double eregi with OR bit


<center>

<?
if(eregi(".+bigtitsfinder.com.+", $HTTP_REFERER) OR eregi(".+scriptschool.com.+", $HTTP_REFERER)){
if(
$action=="true"){
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $senders_email)){
$recipients=array($friend1_email,$friend2_email,$friend3_email);
$urls=array('$url1','$url2','$url3');
if(
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[0]) &&
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[1]) &&
ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $recipients[2])){
$num_recipients=count($recipients);
$subject="$senders_name has sent you some of their favorite sites.";
$body_of_email="$senders_name ($senders_email) has sent you some of their favorite links.\n
$comments\n
$url1
$url2
$url3\n
Enjoy!"
;
$additional_headers="From: $senders_email\n";
for(
$i=0; $i<$num_recipients; $i++){
if(
mail($recipients[$i], $subject, $body_of_email, $additional_headers)){
}else{
print(
"Emails not sent, check php code and try again.");
}
}
}else{
print(
"One of your friends emails is not valid, please try again.");
}
print(
"Emails Sent, Send More?");
}else{
print(
"$senders_email is not a valid email address, please try again.");
}
}
}else{
print(
"Sorry, only surfers from Big Tits Finder and Script School an use this form.");
exit;
}
?>

<h1>Share some URL's with your friends</h1>
Fill out the form below to send your favorite links to 3 friends.
<FORM METHOD="POST" ACTION="<? $PHP_self ?>">
<input type="hidden" name="action" value="true">
<table cellpadding="5"><tr><td>
Your name:</td><td>
<input type="text" name="senders_name" size="25"></td></tr><tr><td>
Your e-mail:</td><td>
<input type="text" name="senders_email" size="35"></td></tr><tr><td>
Friend 1's e-mail:</td><td>
<input type="text" name="friend1_email" size="35"></td></tr><tr><td>
Friend 2's e-mail:</td><td>
<input type="text" name="friend2_email" size="35"></td></tr><tr><td>
Friend 3's e-mail:</td><td>
<input type="text" name="friend3_email" size="35"></td></tr><tr><td>
URL 1:</td><td>
<input type="text" name="url1" size="55"></td></tr><tr><td>
URL 2:</td><td>
<input type="text" name="url2" size="55"></td></tr><tr><td>
URL 3:</td><td>
<input type="text" name="url3" size="55"></td></tr><tr><td>
Comments:</td><td>
<textarea rows="3" cols="35" name="comments"></textarea>
</td></tr></table>
<input type="submit" value="Submit">
</form>

</center>



 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission