?
Solved

Recommend page to friend does not go to confirmation page

Posted on 2005-03-29
7
Medium Priority
?
220 Views
Last Modified: 2013-12-03
Hello

I'm not a php programmer. I barely manage to reconfigure php with mucho help from Experts-Exchange.

Here is the page in question:

http://www.sloanusa.com/recommend.php

When I modified the generic version of the above script (it's a one page php script, no other files, no config file etc.) I was able to give the page a "look" that matched the rest of the site.

But in doing so I must have deleted code that properly sends the web  visitor to a confirmation page.

If you fill out the form you indeed go to the page where on the bottom there is the confirmation but it's hidden below the repeat of the previous page.

Can you modify the code for me so that it goes to a generic thank you page, and then I'll add the HTML to decorate the thank you page to look like the rest of the site.   One additional request, please include the basic html structure in the thank you/confirmation page, so I have a HTML playground to work in.  I.e. <html><head></head><body></body></html>

Thanks for any help!

Rowby
0
Comment
Question by:Rowby Goren
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 9

Author Comment

by:Rowby Goren
ID: 13659289
P.S. Here is the untouched code (or almost untouched code)  downloaded from the orignal site.

<?  
/************* PHPRecommend v 1.3 ***************/
/************************************************/
/*  written by A. Gianotto - 3/28/2000          */
/*  To find out if this is the latest version   */
/*  of this script, email snipe@snipe.net, or   */
/*  visit http://www.snipe.net                  */
/************************************************/
/************************************************/
/*  PHPRecommend may be used freely for private */
/*  or commercial use.  All I ask is that you   */
/*  don't include it in any collections without */
/*  my permission.                              */
/************************************************/
/************************************************/
/*  DESCRIPTION:                                */
/* PHP "Recommend this page to a friend" script */
/*                                              */
/************************************************/
/************************************************/
/* NEW IN VERSION 1.3 - Multiple Email Address Support*/
/* ADDED 6/12/01                                */
/*  
/************************************************/
/************************************************/
/* URL LOGGING:
/* If you wish to use this feature, the only    */
/* additional step you must take is to upload   */
/* a blank text file into the same directory as */
/* this script lives.  For our purposes, we     */
/* have named it "url-log.txt".  You may name   */
/* it whatever you like, but if you change the  */
/* name, be sure to change it in the variable   */
/* below, where it's marked                     */
/*                                              */
/* Also BE SURE TO CHMOD THE TEXT FILE TO 666   */
/* so that the sever can open the file and      */
/* write to it.                                 */
/* ENJOY!                                       */
/************************************************/
/************************************************/
/*  INSTALLATION:                               */
/*  There is no readme or install file with     */
/*  script, because it's so easy to install,    */
/*  you just have to follow the comments in the */
/*  first part of the code                      */
/************************************************/
/************************************************/

// Change the variable below to "no" if you do not wish to write
// the data to a text log
$logging="no";

// Enter the website administrators email address here
$adminaddress = "rowby@rowby.com";

// Enter the company name or site name here
$sitename = "Sloan Management - Jeffrey Sloan";

// Enter the address of your website here
$siteaddress ="http://www.sloanusa.com";


// Unless you are changing the verbage of the printed message,
// there are no further configurations that need to be done  
// past this point, except editing the path to your footer includes

// If you do not use header and footer files, you can just replace
// the include calls with your HTML, but be sure to close the PHP tags
// before and after the HTML, so you don't get parse errors.

?>
<html>
<head>
<title>Sloan Management - Jeffrey Sloan</title>



<?php
IF ($action=="") {
?>

<?
$referer = getenv("HTTP_REFERER");  

?>
<p>To send a link to Jeffery Sloan's Management page and a brief message fill out the  
form below.  All fields except the comments are required.
</p>
<FORM METHOD=POST ACTION="<? echo "$PHP_SELF"; ?>">
  <TABLE BORDER="0" CELLSPACING="3" CELLPADDING="3">
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Your Name:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="yname"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Your Email:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="yemail"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Friend  Name:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="fname[1]"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Friend  Email:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="femail[1]"></FONT></TD>
</TR>

<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="-1">Additional Comments:</FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="3"><textarea NAME="comments" rows="3"></TEXTAREA></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="3"><INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"; ?>"><INPUT  
TYPE="submit" NAME="action" VALUE="Send"></FONT></TD>
</TR>
</TABLE>

</FORM>
    <BR>
    <BR>
    <BR>
    <BR>
    <BR>


<?

} ELSEIF ($action="Send") {

    if (($yname=="") || ($fname=="")  || ($femail=="")|| ($yemail==""))  {
print "Please use your back button and complete all of the required form fields, then resubmit.<br><br><br><br><br><br><br><br><br><br><br>";
} else {
        print "Your recmmendation to the following people has been sent:<br><br> ";
            // cycle through the emal addresses and names
        $items="5";
        $tally="";
        for ($numitems=0; $numitems < $items; $numitems++) {
              if (($fname[$numitems]!="") && ($femail[$numitems]!=""))  {
                mail("$femail[$numitems]","$yname went to $sitename and recommended you check this out","$fname[$numitems] \n\n $yname stopped by $sitename and thought you would find the following URL of interest:\n \nURL: $url \n\n Additional Comments: \n------------------------------------ \n$comments \n------------------------------------\n\nThank you! \n$sitename \n$adminaddress \n$siteaddress","FROM:$yemail");


            // NEW IN VERSION 1.2 - LOGGING TO A TEXT FILE - 7/31/00
            // this writes the url, comments, and email address
            // to a text database so you can easily track which
            // pages are being recommended most often

            // Be sure to upload the blank text file that the
            // data will write to.  In this case, we named it url-log.txt
            // If you name your blank file url-log.txt, no changes are needed here.
            // If you decide to use a different filename, you must change the
            // variable below.
               
                IF ($logging=="yes") {
                $filename="url-log.txt";

                // Nothing needs ot be changed here

                $fl=fopen($filename,"a+");
                // sets the pipe delimiters
                fwrite($fl,"'$url'|'$femail[$numitems]'|'$yemail'|'$comments'\n");
                fclose($fl);
                }
              $tally.="$fname[$numitems], ";
              }
         }

?>
<P>Your recommendation has been sent to <?php echo "$tally"; ?> </p>

    <p><B><A HREF="<? echo "$url"; ?>">GO BACK</A></B> </p>
    <BR>
    <BR>
<?
}

}




// end of script

// *********************************************
// Making it work on your page:
// Just put a link to phprecommend.php (or whatever you name
// the above file), and the script  
// does the rest!

?>


0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13659357
First thing I see:
Change:

} ELSEIF ($action="Send") {

TO:

} ELSEIF ($action=="Send") {
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 13659408
Hi I made that change.  Thanks

The page still remains the same except for what should be the confirmation page on the bottom of the page.

Again, an alternative is, upon submit, to go to a different confirmaiton page (instead of staying on the recommend.php) page -- if that's the easier solution.
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
LVL 11

Accepted Solution

by:
matt_mcswain earned 2000 total points
ID: 13659559
Sorry, for the delay. This scripts a mess. I changed loads, so let me know if you have any problems.
I moved the form mailer above, and if the forms filled out it tries to send the mails and redirects to confirmation.php
If not, it stays at the current page and displays an error message.

<?php
/************* PHPRecommend v 1.3 ***************/
/************************************************/
/*  written by A. Gianotto - 3/28/2000          */
/*  To find out if this is the latest version   */
/*  of this script, email snipe@snipe.net, or   */
/*  visit http://www.snipe.net                  */
/************************************************/
/************************************************/
/*  PHPRecommend may be used freely for private */
/*  or commercial use.  All I ask is that you   */
/*  don't include it in any collections without */
/*  my permission.                              */
/************************************************/
/************************************************/
/*  DESCRIPTION:                                */
/* PHP "Recommend this page to a friend" script */
/*                                              */
/************************************************/
/************************************************/
/* NEW IN VERSION 1.3 - Multiple Email Address Support*/
/* ADDED 6/12/01                                */
/*  
/************************************************/
/************************************************/
/* URL LOGGING:
/* If you wish to use this feature, the only    */
/* additional step you must take is to upload   */
/* a blank text file into the same directory as */
/* this script lives.  For our purposes, we     */
/* have named it "url-log.txt".  You may name   */
/* it whatever you like, but if you change the  */
/* name, be sure to change it in the variable   */
/* below, where it's marked                     */
/*                                              */
/* Also BE SURE TO CHMOD THE TEXT FILE TO 666   */
/* so that the sever can open the file and      */
/* write to it.                                 */
/* ENJOY!                                       */
/************************************************/
/************************************************/
/*  INSTALLATION:                               */
/*  There is no readme or install file with     */
/*  script, because it's so easy to install,    */
/*  you just have to follow the comments in the */
/*  first part of the code                      */
/************************************************/
/************************************************/

// Change the variable below to "no" if you do not wish to write
// the data to a text log
$logging="no";

// Enter the website administrators email address here
$adminaddress = "rowby@rowby.com";

// Enter the company name or site name here
$sitename = "Sloan Management - Jeffrey Sloan";

// Enter the address of your website here
$siteaddress ="http://www.sloanusa.com";


// Unless you are changing the verbage of the printed message,
// there are no further configurations that need to be done  
// past this point, except editing the path to your footer includes

// If you do not use header and footer files, you can just replace
// the include calls with your HTML, but be sure to close the PHP tags
// before and after the HTML, so you don't get parse errors.
if (isset($_POST['action'])) {

    if (empty($_POST['yname']) || empty($_POST['fname'][1])  || empty($_POST['femail'][1]) || empty($_POST['yemail']) )  {
 $errMsg = "Please complete all of the required form fields, then resubmit.<br><br><br><br><br><br><br><br><br><br><br>";
} else {
     
       
            // cycle through the emal addresses and names
        $items="5";
        $tally="";
        for ($numitems=0; $numitems < $items; $numitems++) {
              if (isset($_POST['fname'][$numitems]) && isset($_POST['femail'][$numitems]))  {
                $subject = $_POST['yname']." went to $sitename and recommended you check this out";
                        $message = $_POST['fname'][$numitems]." \n\n {$_POST['yname']} stopped by $sitename and thought you would find the following URL of interest:\n \nURL: $url \n\n Additional Comments: \n------------------------------------ \n$comments \n------------------------------------\n\nThank you! \n$sitename \n$adminaddress \n$siteaddress";
                        @mail($_POST['femail'][$numitems],$subject,$message,"FROM:{$_POST['yemail']}");


            // NEW IN VERSION 1.2 - LOGGING TO A TEXT FILE - 7/31/00
            // this writes the url, comments, and email address
            // to a text database so you can easily track which
            // pages are being recommended most often

            // Be sure to upload the blank text file that the
            // data will write to.  In this case, we named it url-log.txt
            // If you name your blank file url-log.txt, no changes are needed here.
            // If you decide to use a different filename, you must change the
            // variable below.
               
                IF ($logging=="yes") {
                $filename="url-log.txt";

                // Nothing needs ot be changed here

                $fl=fopen($filename,"a+");
                // sets the pipe delimiters
                fwrite($fl,"'$url'|'".$_POST['femail'][$numitems]."'|'".$_POST['yemail']."'|'$comments'\n");
                fclose($fl);
                }
              $tally.=$_POST['fname'][$numitems].", ";
              }
         }
             header('Location: confirmation.php');
             exit;
               
  }

}

?>
<html>
<head>
<title>Sloan Management - Jeffrey Sloan</title>

</head>
<body>
<?
$referer = getenv("HTTP_REFERER");  
echo isset($errMsg) ? $errMsg : '';
?>
<p>To send a link to Jeffery Sloan's Management page and a brief message fill out the  
form below.  All fields except the comments are required.
</p>
<FORM METHOD=POST ACTION="<? echo $_SERVER['PHP_SELF']; ?>">
  <TABLE BORDER="0" CELLSPACING="3" CELLPADDING="3">
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Your Name:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="yname"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Your Email:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="yemail"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Friend  Name:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="fname[1]"></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif" SIZE="-
1">Friend  Email:</FONT></TD>
    <TD VALIGN="TOP"><FONT FACE="Arial, Helvetica, Verdana, Sans Serif"  
SIZE="3"><INPUT TYPE="text" NAME="femail[1]"></FONT></TD>
</TR>

<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="-1">Additional Comments:</FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="3"><textarea NAME="comments" rows="3"></TEXTAREA></FONT></TD>
</TR>
<TR>
    <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="3"><INPUT TYPE="hidden" NAME="url" VALUE="<? echo "$referer"; ?>"><INPUT  
TYPE="submit" NAME="action" VALUE="Send"></FONT></TD>
</TR>
</TABLE>

</FORM>
    <BR>
    <BR>
    <BR>
    <BR>
    <BR>
</body>
</html>
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 13660720
HI  

I put up the page, and added the thankyou page url, and the email does get sent, but the page goes not redirtect to the confirmatin/thank you page.  Below is where I added the URL:

  <TD VALIGN="TOP" COLSPAN="2"><FONT FACE="Arial, Helvetica, Verdana, Sans  
Serif" SIZE="3"><INPUT TYPE="hidden" NAME="thankyou.htm" VALUE="<? echo "$referer"; ?>"><INPUT  
TYPE="submit" NAME="action" VALUE="Send"></FONT></TD>
</TR>

Below is the link to the page:
http://sloanusa.com/recommend.php
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13663448
So, you want to send it to thankyou.htm?
Just change this line.

header('Location: confirmation.php');

to

header('Location: thankyou.htm');
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 13664329
Perfecto Matt!

I appreciate your Expert Help!

Rowby
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question