Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    popup - $referrer losing focus

    Hi,

    Please help a newbiegrrl out?

    I am trying to use the GateQuest's Site Recommender (inc.recommend.php - popup version), which I modified slightly to use $referrer. It's a real purty script, BUT it doesn't retain focus: The $referrer URL is fine in the popup window, BUT the script sends the recommend.popup.php URL in the resulting email.

    Hard-coding the URL is not practical since I have over 500 pages to add this script to after the bugs are worked out.

    Here is my test page:
    http://www.radioproject.org/archive/2005/2005TEST2.html (click on the link above the photo on the right-hand side)

    Please, please help? I am new to PHP/Java/popups and this is driving me nuts, because I feel like am SO close.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Can you show us some code?

    And the referer header may not always be set by the browser, so sometimes you script will not work.

  • #3
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    re: popup - $referrer losing focus

    OK here's the include...

    <?php

    //*******************************************************************
    // File: inc.recommend.php © GateQuest, Inc. - gatequest.net
    // Author: D Stewart (dstewart@gatequest.net)
    // Date: 11-07-2004
    // Version: 2.2
    //*******************************************************************


    /* Config Section */


    $sitename = 'National Radio Project'; // Name of your site.

    $url = 'http://www.radioproject.org'; // Web address for your site.

    $webmasterEmail = 'webeditor@radioproject.org'; // Your email address.

    $receiveNotifications = 1; // 0=no, 1=yes. If yes, you will be notified of the recipients and the message.

    $errorstyleclass = 'error'; // The class that specifies the CSS error color.

    $numberofrecipients = 5; // Number of recipient email address fields to be displayed.

    $referrer = $_SERVER['HTTP_REFERER']; //recommend the current page they are on instead of the entire site.

    $emailsubject = 'web page recommendation from [name] ([email])'; //Email subject line (recommend current page).

    $emailmessage = "Hello,\n\r[name] thought you would like to visit the following page: $referrer"; // Message in email body (recommend current page.

    /* End Config */


    $mailsent = false;
    $errormessages = array();
    $errorfields = array();

    if(count($_POST) > 0) {
    if(get_magic_quotes_gpc()) $_POST = strip_magic_quotes($_POST);

    if(empty($_POST['name'])) {
    $errormessages[] = 'Please enter your name.';
    $errorfields[] = 'name';
    }

    if(empty($_POST['email'])) {
    $errormessages[] = 'Please enter your email address.';
    $errorfields[] = 'email';
    } else {
    if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $_POST['email'])) {
    $errormessages[] = 'Please enter a proper email address for yourself.';
    $errorfields[] = 'email';
    }
    }

    for($i=1, $count=count($_POST['to']); $i<=$count; $i++) {
    if(empty($_POST['to'][$i])) unset($_POST['to'][$i]);
    }

    if(empty($_POST['to'])) {
    $errormessages[] = 'Please enter at least one friend\'s email address.';
    $errorfields[] = 'to[1]';
    } else {
    foreach($_POST['to'] as $key=>$value) {
    if(!empty($value)) {
    if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $value)) {
    $errormessages[] = 'Please enter email address #' . $key . ' proper.';
    $errorfields[] = "to[$key]";
    }
    }
    }
    }

    // Now if there are no errors, send the message.
    if(empty($errormessages)) {
    $emailsubject = str_replace('[name]', $_POST['name'], $emailsubject);
    $emailsubject = str_replace('[email]', $_POST['email'], $emailsubject);
    $emailmessage = str_replace('[name]', $_POST['name'], $emailmessage);
    $emailmessage = str_replace('[url]', $url, $emailmessage);
    $emailmessage .= "\r\n\n" .
    $_POST['message'] .
    "\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at $url. " .
    "If you believe this message was received on error, please disregard it.";
    $emailheader = "From: " . $_POST['email'] . "\r\n" .
    "Reply-To: " . $_POST['email'] . "\r\n" .
    "X-Mailer: GateQuest php Site Recommender\r\n";

    $sent = array();
    foreach($_POST['to'] as $key=>$value) {
    if(mail($value, $emailsubject, $emailmessage, $emailheader)) {
    $sent[] = $value;
    }
    }
    $failed = array_diff($_POST['to'], $sent);
    $mailsent = true;

    if($receiveNotifications) {
    $subject = 'Someone recommended your site';
    $message = 'This is a message to tell you that ' . $_POST['name'] . ' (' . $_POST['email'] .')' .
    ' sent a website recommendation to ' . implode(', ', $sent) .
    "\n\nMessage: " . $_POST['message'];
    $headers = 'From: ' . $webmasterEmail . "\r\n" .
    'X-Mailer: GateQuest php Site Recommender';
    @mail($webmasterEmail, $subject, $message, $headers);
    }
    }
    }

    ?>

    <?php
    if($mailsent) {
    echo empty($sent) ? '' : '<p>Message was successfully sent to ' . implode(', ', $sent) . '</p>';
    echo empty($failed) ? '' : '<p>Message was NOT successfully sent to ' . implode(', ', $failed) . '<br />Please try again later!</p>';
    echo '<p>Thank you very much for recommending this ' ,'<br />', $sitename , ' web page', '</p>';
    } else {
    if(count($_POST) > 0 && !empty($errormessages)) {
    echo '<table><tr><td><span class="' , $errorstyleclass , '">';
    echo 'The following error(s) occured:<br />';
    foreach($errormessages as $value) {
    echo ' &nbsp; &nbsp; &raquo; ' ,$value , '<br />';
    }
    echo '</span><br /></td></tr></table>';
    }
    ?>
    <link href="/css/styles.css" rel="stylesheet" type="text/css" />


    <table width="269"align="center" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td background="/images/z_body-corner-ul.gif"><img src="/images/z_blank.gif" width="5" height="5" /></td>
    <td background="/images/z_body-corner-top.gif"><img src="/images/z_blank.gif" width="100" height="5" /></td>
    <td background="/images/z_body-corner-ur.gif"><img src="/images/z_blank.gif" width="10" height="5" /></td>
    </tr>
    <tr>
    <td background="/images/z_body-corner-left.gif"><img src="/images/z_blank.gif" width="5" height="50" /></td>
    <td valign="top" background="/images/z_body-background.gif">
    <table width="254" border=0>
    <tr><td width="266" valign="top">
    <table width="248" align="center">
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <tr>
    <td colspan="2"><div class="bodyArea">
    <h3>National Radio Project</h3>
    <p><strong>Recommend this page:</strong> <br />
    <?php echo $referrer; ?></div></td>
    </tr>
    <tr>
    <td width="85"><div class="bodyArea">Your Name:</div></td>
    <td width="151"><input name="name" type="text" class="<?php echo in_array('name', $errorfields) ? $errorstyleclass : ''; ?>" value="<?php echo isset($_POST['name']) ? $_POST['name'] : '';?>">
    </td>
    </tr>
    <tr>
    <td><div class="bodyArea">Your Email:</div></td>
    <td><input name="email" type="text" class="<?php echo in_array('email', $errorfields) ? $errorstyleclass : ''; ?>" value="<?php echo isset($_POST['email']) ? $_POST['email'] : '';?>">
    </td>
    </tr>
    <tr>
    <td colspan="2"><div class="bodyArea">Recipient Email Addresses&nbsp;&nbsp;º at least one º<br />
    <br /></div></td>
    </tr>
    <tr>
    <td><div class="bodyArea"><strong>1.</strong></div></td>
    <td><input name="to[1]" type="text" class="" value=""></td>
    </tr>
    <?php
    for($i=2; $i<=$numberofrecipients; $i++) {
    $value = isset($_POST['to'][$i]) ? $_POST['to'][$i] : '';
    $class = in_array("to[$i]", $errorfields) ? $errorstyleclass : '';
    echo " <tr>\n";
    echo ' <td class="formtext">' , $i , ".</td>\n";
    echo ' <td><input type="text" name="to[', $i ,']" value="', $value ,'" class="', $class ,"\"></td>\n";
    echo " </tr>\n";
    }
    ?>
    <tr>
    <td colspan="2"><div class="bodyArea">Your Message&nbsp;&nbsp;º optional º<br />
    </div>
    <textarea name="message" rows="5" cols="31" class="<?php echo in_array('messsage', $errorfields) ? $errorstyleclass : ''; ?>"><?php echo isset($_POST['message']) ? $_POST['message'] : '';?></textarea>
    </td>
    </tr>
    <tr>
    <td colspan="2"><table>
    <tr>
    <td><input class="send" type="submit" value="Send Message" /></td>
    <td>&nbsp;</td>
    <td><input class="reset" type="reset" value="Reset Form" /></td>
    </tr>
    </table></td>
    </tr>
    </form>
    </table></td>
    </tr>
    </table>
    </td>
    <td width="49" background="/images/z_body-corner-right.gif">&nbsp;</td>
    </tr>
    <tr>
    <td width="5" background="/images/z_body-corner-bl.gif"><img src="/images/z_blank.gif" width="5" height="9" /></td>
    <td width="256" background="/images/z_body-corner-bottom.gif"><img src="/images/z_blank.gif" width="100" height="9" /></td>
    <td width="49" background="/images/z_body-corner-br.gif"><img src="/images/z_blank.gif" width="10" height="9" /></td>
    </tr>
    </table>


    <?php
    }
    ?>

    <?php
    function strip_magic_quotes($arr) {
    foreach($arr as $k => $v) {
    if(is_array($v)) {
    $arr[$k] = strip_magic_quotes($v);
    } else {
    $arr[$k] = stripslashes($v);
    }
    }
    return $arr;
    }
    ?>

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    Pakistan
    Posts
    207
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi honey
    if u r looking for this type of help, then its very difficult that u get any result.
    try to send in small pieces.
    i m sure u 'll not mind it.
    Regards,
    Aamir.
    God helps those who help others.

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    You need something like:

    Code:
    if(isset($_POST['referer'])){
    $referrer = $_POST['referer'];
    }
    else
    {
    $referrer = $_SERVER['HTTP_REFERER']; //recommend the current page they are on instead of the entire site.
    }
    
    // instead of:
    
    $referrer = $_SERVER['HTTP_REFERER']; //recommend the current page they are on instead of the entire site.
    and to add
    Code:
    echo '<input type="hidden" name="referer" value="' . $referer . '">';
    into the form.

    (This isn't tested!)

    EDIT: The reason it does this is that when the form is submitted the $referer value is lost, as the page has changed and now it is set the the forms page URL instead of the first referer. To stop this you det a hidden form field and then if it's set put that instead of the referer.
    Last edited by schleppel; 06-08-2005 at 03:38 PM.

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by amir
    hi honey
    if u r looking for this type of help, then its very difficult that u get any result.
    try to send in small pieces.
    i m sure u 'll not mind it.
    Regards,
    Aamir.
    No, I find it easier to sift through the whole code than one piece without errors.
    Thank you for playing, please try again.

    As for the problem, $_SERVER['HTTP_REFERER'] isn't realible as it isn't aslways set. For what you are doing, I'd use a session and set the page name and url at the top of each page. But that's just me.

  • #7
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    we're almost there, schleppel

    OK, that solved the problem for Mozilla, Netscape and IE5 for Mac - THANK YOU. But it's not working on IE6 for PC - $referrer isn't passed to the popup or the email. ??? I'm not sure how to "use a session and set the page name and url at the top of each page." ?
    Last edited by NatRadWebgrrl; 06-14-2005 at 05:16 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •