9999 Posted April 8, 2009 Share Posted April 8, 2009 I link to a "tell a friend" or "share page" script by using this link which grabs the url of the page the visitor is on (the original script uses a refferer which is often blocked.) <a href="http://www.mysite.com/friend.php?sharepage=http://www.mysite.com<?php echo $_SERVER['REQUEST_URI']; ?>">Share this page</a> In my friend script, I use GET to retrive the url to be shared then I assign it to $url2. The user then enters their info and the info of the people to share the page with. When they hit submit, the form posts to itself and $url2 is passed as a hidden variable "share_url" which I assign to $url3 for printing in the email. My problem is the shared address is cutoff at the first "&" if I have an address like: "http://www.mysite.com/hello.php?page_id=12&topic=news&date=apr09" All I would get is "http://www.mysite.com/hello.php?page_id=12" What am I doing wrong? This is my friend.php script: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Share page</title> <link rel="stylesheet" href="recommend.css" type="text/css"> </head> <body> <table width="100%" height="100%"> <tr> <td align="center" valign="middle"> <?php //******************************************************************* // File: inc.recommend.php © Big Lick Media - BigLickMedia.com // Author: D Stewart // Update: 04-16-2006 // Version: 2.4.4 //******************************************************************* /* Config Section */ //$referrer = $_SERVER['HTTP_REFERER']; $sitename = 'My Site'; // Name of your site. $url = 'http://www.mysite.com'; // Web address for your site. $url2 = $_GET['sharepage']; // Actual page to be sent $url3 = $_POST['share_url']; // url was passed as hidden variable $webmasterEmail = '[email protected]'; // 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 = 10; // Number of recipient email address fields to be displayed. $emailsubject = 'Great Website'; //Email subject line. $emailmessage = "Hello,\n\r[name] thought you would like to visit the following web page: $url3"; // Message in email body. /* 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 = str_replace('[share_url]', $_REQUEST['share_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 the website: $url. "; $emailheader = "From: " . $_POST['email'] . "\r\n" . "Reply-To: " . $_POST['email'] . "\r\n" . "X-Mailer: Big Lick Media - 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 = 'Site recommended'; $message = 'This is a message to tell you that ' . $_POST['name'] . ' (' . $_POST['email'] .') ' . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . ' sent a website recommendation to ' . implode(', ', $sent) . "\n\nMessage: " . $_POST['message']; $headers = 'From: ' . $_POST['email'] . "\r\n" . 'X-Mailer: Big Lick Media - 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 sharing ' , $sitename , '</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 ' » ' ,$value , '<br />'; } echo '</span><br /></td></tr></table>'; } ?> <table> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <tr> <td class="formtexttitle" colspan="2"> Recommend <?php echo $sitename; ?> to your friends and family</td> </tr> <tr> <td class="formtext">Your Name:</td> <td><input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : ''; ?>" class="<?php echo in_array('name', $errorfields) ? $errorstyleclass : ''; ?>" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';" /> </td> </tr> <tr> <td class="formtext">Your Email:</td> <td><input type="text" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?>" class="<?php echo in_array('email', $errorfields) ? $errorstyleclass : ''; ?>" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';" /> </td> </tr> <tr> <td colspan="2"> Recipient Email Addresses <span class="basefontblue">(Enter at least one)<br/> (To enter more than 10, simply revisit this page)<br/></span><br/><br /></td> </tr> <tr> <td class="formtext">1.</td> <td><input type="text" name="to[1]" value="" class="" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';" /></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 ,"\" onfocus=\"this.style.borderColor='#0072BC';\" onblur=\"this.style.borderColor='silver';\" /></td>\n"; echo " </tr>\n"; } ?> <tr> <td colspan="2">Your Message (<span class="basefontblue">Optional</span>)<br /> <textarea name="message" rows="4" cols="40" class="<?php echo in_array('messsage', $errorfields) ? $errorstyleclass : ''; ?>" onfocus="this.style.borderColor='#0072BC';" onblur="this.style.borderColor='silver';"><?php echo isset($_POST['message']) ? $_POST['message'] : '';?></textarea> </td> </tr> <input type="hidden" name="share_url" value="<? echo $url2; ?>" /> <tr> <td colspan="2"> <table> <tr> <td><input class="send" type="submit" value="Send Now" /></td> <td class="formtext"> </td> <td><input class="reset" type="reset" value="Reset Form" /></td> </tr> </table> </td> </tr> </form> </table> <?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; } ?> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/153209-share-page-script-problem/ Share on other sites More sharing options...
Zhadus Posted April 8, 2009 Share Posted April 8, 2009 You can't pass it in the address bar like that. Change the & character to something else unused that PHP does not use and then use a string replace on the new page before it sends the email. Link to comment https://forums.phpfreaks.com/topic/153209-share-page-script-problem/#findComment-804936 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.