Current location: Hot Scripts Forums » Programming Languages » PHP » Share page script problem


Share page script problem

Reply
  #1 (permalink)  
Old 04-08-09, 01:11 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Share page script problem

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.)

Code:
<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:

PHP Code:

<!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 'me@mysite.com';        // 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) > && !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>'
    } 
?> 

<table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <tr>
        <td class="formtexttitle" colspan="2">&nbsp;&nbsp;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">&nbsp;Recipient Email Addresses&nbsp;&nbsp;<span class="basefontblue">(Enter at least one)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(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&nbsp;&nbsp;(<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">&nbsp;</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>
Reply With Quote
  #2 (permalink)  
Old 04-09-09, 01:04 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
The problem you are having is the GET arguments in the shared site URL.
The way you have it written, they are treated as separate $_GET variables.
You need to change the question mark (?) and the and signs (&) to something other than their literal values.

In this example I have the code change the question mark (?) with a star (*) and the and signs (&) with double stars (**).

Then on the receiving page I change them back.

PHP Code:

<?php
$addr 
= empty($_POST["addr"])?"":$_POST["addr"];
if(
$addr)
{
 
$args str_replace("?","*",str_replace("&","**",$addr));
 echo 
"<a href='http://www.mysite.com/friend.php?sharepage=".$args."'>Share this page</a>";
 }
else{
?>
<form action="#" method="post">
Enter Address To Share: <input type="text" name="addr"><br />
<input type="submit" value="Submit">
</form>
<?php
}
?>
friend.php
PHP Code:

<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 = empty($_GET['sharepage'])?"":$_GET['sharepage'];    // Actual page to be sent
$url2 str_replace("*","?",str_replace("**","&",$url2));
$url3 = empty($_POST['share_url'])?"":$_POST['share_url'];   // url was passed as hidden variable

$webmasterEmail 'me@mysite.com';        // 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) > && !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>';
    }
?>

<table>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
    <tr>
        <td class="formtexttitle" colspan="2">&nbsp;&nbsp;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">&nbsp;Recipient Email Addresses&nbsp;&nbsp;<span class="basefontblue">(Enter at least one)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(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&nbsp;&nbsp;(<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="<?php echo $url2?>" />
    <tr>
        <td colspan="2">
            <table>
                <tr>
                    <td><input class="send" type="submit" value="Send Now" /></td>
                    <td class="formtext">&nbsp;</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>
__________________
Jerry Broughton
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Your Own Profitable and VERY unique eBusiness Voltaire General Advertisements 3 03-30-10 06:36 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
php script selling page www.infinitcreations.net, rate it? urlguy Website Reviews 3 04-30-05 07:48 AM
Looking for simple "Password" script to access a hidden page. Nigel DV Script Requests 16 04-12-05 07:39 PM


All times are GMT -5. The time now is 08:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.