Jump to content


Photo

Send page to a friend


  • Please log in to reply
23 replies to this topic

#1 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 18 April 2006 - 10:13 PM

Hi all,
I have a client who would like a "Send this page to a friend" sort of thing. I can figure out how to do the basic stuff (the form, sending th email etc.) but how do I do it, so that it gets the page that the user is on?
Thanks!

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 18 April 2006 - 11:52 PM

Try this, my furry friend:

$current_url = 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];

PHP Ninja

#3 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 19 April 2006 - 02:30 AM

Thanks!

However, I've run into some problems. Right now I have a PHP page with this code (I'm just playing around with this right now)

<?php
echo "$_SERVER[HTTP_REFERER]";
?>

This works just fine when clicking a norma link to the page (it shows the HTTP referer), however, when accessed through a popup (ie click a link and a popup window pops up with the page) it doesn't show anything. Could you help me with this?
Here's the code on the page with the popup window link.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>
</head>

<body>


<p><A 
   HREF="test.php" 
   onClick="return popup(this, 'notes')">my popup</A>
</p>

</body> 

</html>

Thanks so much for your help!

P.S. How did you know the Boerboel is a dog? Not many people have heard of that breed. :)

#4 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 19 April 2006 - 06:10 PM

Anybody? Why will it not display the HTTP referer, when the page is accessed through a Javascript popup window?
Thanks!

#5 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 19 April 2006 - 07:10 PM

You can't use the HTTP Referrer with a JS popup because no headers are sent if you create the window purely through JS.

All you have to do is send the URL as an argument to the JS function.

Info: PHP Manual


#6 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 20 April 2006 - 06:14 PM

How do I send the URL as an argument to the JS function? I'm a relative newbie to PHP, and REALLY an newbie with JS.
Thanks!

#7 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 20 April 2006 - 06:34 PM

[a href=\"http://www.webdevelopersnotes.com/tutorials/javascript/learning_javascript_functions.php3\" target=\"_blank\"]http://www.webdevelopersnotes.com/tutorial..._functions.php3[/a]
that'll tell you everything you need to know.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#8 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 23 April 2006 - 01:57 AM

Hi,
Thanks for the link. However, I'm still not sure how to pass the referring URL to the JS popup window. I'm still learning PHP, and am pretty much clueless with JS. Would you mind giving me some code or somethiing to pass the referring URL to the popup window?
Thanks for bearing with this newbie.

#9 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 23 April 2006 - 02:09 AM

give me until tonight I am off right now and don't have a lot of time. I will work up something quick for you tonight, check again in like 5 hours.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 23 April 2006 - 03:46 AM

<BODY onLoad="javascript: alert('http://www.w3schools.com')">
this it the html tag here, it will go within your body tag. at the beginning.
simply replace the url with your own, if that is what you are trying to do, if this is not what you wanted, well run the script if you get the desired affect then ok, if not then let me know exactly what you wanted to happen this will create a pop up window with the url on it, but I am not sure if that is what you meant, if not relay back to me exactly what you are wanting to happen, and next time I check my email i will come here and see what I can do.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 23 April 2006 - 01:03 PM

Thanks, but that's not what I wanted. Let me explain what I'm trying to achieve here.....

OK, on each page on this clients site, there will be a "Send this page to a friend" link. When a user clicks on it, a javascript window will popup, with a form, with box reciepents email address(es), optional message etc. I would like to have the HTTP Referer (i.e., the URL to the page that they clicked on the "Send this page to a link thing) to be in a hidden form field. I know how to do this with a regular page, using PHP, but it won't work with the JS popup window. Do you understand what I'm wanting now? If not, let me know, and I'll try to explain some more.
Thank you so much for your help and pateince... it's greatly appreciated!!!!!

#12 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 23 April 2006 - 01:51 PM

By what I have done with javascript, it is probably best if you didn't do that. Javascript isn't secure is any information going through that, and also you have to understand, with javascript no matter what some of your viewers will not have access to that, it is good to not put anything of utmost importance in javascript, as anyone with some older browsers that don't support javascript or if they have it turned off then what you are doing they won't see. Javascript is for preloading images, and dropdown menus with some peolpe that want it, as long as you have other links as well, and javascript isn't picked up in search engines, rethink wwhether you want to do this or not, but what you can do. and unfortunately you can only create 3 types of popup windows, alert, prompt, and another. Its with an ok button, with ok and cancel, and with typing in 1 thing. You can't create a form in javacsript popup by what I know I have never seen anyone do this before, having a form popup you can just have your form come up in another window with _blank, and then have it send it that way, and tell the window to close when they click the submit button by using the javascript onunload function. Let me know how this works.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#13 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 23 April 2006 - 02:35 PM

Thanks for your help businessman. I think I'll just open it with _blank thing.

Thanks so much for all of your help!

#14 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 23 April 2006 - 04:08 PM

that's only with javascript though there are other types of browser side scripting I am not saying it can't be done, just not with javascript. Try www.w3schools.com, over on the left you will see javascript, all those other languages in that section are all browser side scripting languages, check those. If not try php./

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#15 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 23 April 2006 - 07:10 PM

One more question....

OK, I know how to get the referring URL, but is there anyway that I can get the referring pages title using PHP?
Thanks!

#16 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 23 April 2006 - 09:50 PM

Oh well, forget the getting the page title thing.....
OK, I'm almost done with this thing. However, I'm running into a problem with the section of code from the php page which sends the email after the form is submitted.

if (!$_POST['optionalmessage'])
$optionalmessage = "No personal message";
} else {
$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";

There's a textarea on the form. What I'm trying to achieve with this code, is if there is now text submitted from the textarea to display "No personal message" and if there is some text to display "A personal message from your friend: blah blah blah" In place of the blah blah blah would be the message from the person. However, I get this error when I test it out...

Parse error: syntax error, unexpected '}' in /home/morning/public_html/sendfriend.php on line 18

I'm obviously not a PHP guru, but I don't see anything wrong with my } else { (which is what is on line 18.
Thanks for your help!

[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]EDIT:[!--colorc--][/span][!--/colorc--] Here's all of the php code from the page which sends the form:

<?php
$name = $_POST['name'];
$recipient1 = $_POST['recipient1'];
$recipient2 .= $_POST['recipient2'];
$recipient3 .= $_POST['recipient3'];
$recipient4 .= $_POST['recipient4'];
$recipient5 .= $_POST['recipient5'];
if (!$_POST['optionalmessage'])
$optionalmessage = "No personal message";
} else {
$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";
$URL = $_POST['URL'};
// initialize a variable to 
   // put any errors we encounter into an array
   $errors = array();
     // check to see if a name was entered
   if (!$_POST['name'])
      // if not, add that error to our array
      $errors[] = "Name is required";
      // check to see if 1 recipient was entered
      if ($_POST['recipient1'])
      //if not add that error
      $errors[] = "At least one recipient is required";
               // if there are any errors, display them
   if (count($errors)>0){
      echo "<strong>ERROR:<br>\n";
      foreach($errors as $err)
        echo "$err<br>\n";
   } else {
// no errors, so we build our message
// Sends form
$to = $recipient1;
$to .= $recipient2;
$to .= $recipient3;
$to .= $recipient4;
$to .= $recipient5;
$subject = "$name thinks you should check out this site!";
$msg = "$name thought you might be interested in this page <a href='$URL'</a>' 
$optionalmessage";
if (mail($to, $subject, $msg, "From: <removed>"))
         echo "Thanks for your message!  Please note, that sometimes errors may occur and we may not receive your email.  If you do not receive a prompt reply, please send an email to <email removed>.  Please state that you filled out the form, but did not receive a reply";
      else
         echo "An unknown error occurred.  Please try again.  If you receive this error multiple times, please email the webmaster at <email removed>";
   }
?>


#17 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 24 April 2006 - 04:09 AM

not that I know of
there is a way to catch the url of where they are coming from, but it comes blank if they typed in the url. You can also tell if they come from a search engine. There could be a way to check the title. I am checking now.
[a href=\"http://www.webmasterworld.com/forum88/517.htm\" target=\"_blank\"]http://www.webmasterworld.com/forum88/517.htm[/a]
Check this forum here, this has a deep discussion on it,and it tells some about how to get the referrer title, but you have to take the time to look over the whole post, if this doesn't help let me know, and on monday I will create you a script to do it, if it's possible when I start my work schedule, let me know whether this works or not, and wait for me to respond on monday I will post saying I am starting and I will post again with the results. Let me know whether that posts works or not by sometime mid tomorrow, so I have time to finish the script for you.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#18 Roberto

Roberto
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationLondon, England

Posted 24 April 2006 - 08:38 AM

[!--quoteo(post=367789:date=Apr 23 2006, 10:50 PM:name=Boerboel649)--][div class=\'quotetop\']QUOTE(Boerboel649 @ Apr 23 2006, 10:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Oh well, forget the getting the page title thing.....
OK, I'm almost done with this thing. However, I'm running into a problem with the section of code from the php page which sends the email after the form is submitted.

if (!$_POST['optionalmessage'])
$optionalmessage = "No personal message";
} else {
$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";

[/quote]

You are missing { and }
ie


if (!$_POST['optionalmessage'])
{
$optionalmessage = "No personal message";
} else {
$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";
}

*************************************
Mad Mouse Media Web Design
t: (+34) 610 837 558
e: rob@madmousemedia.co.uk
w: www.madmousemedia.co.uk
w: www.madmouseart.com *************************************

#19 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 24 April 2006 - 02:50 PM

the guy who responded up there is right, that would probably be where you problem is.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#20 Boerboel649

Boerboel649
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 25 April 2006 - 02:14 AM

Thanks Roberto, but now it's giving me this error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/morning/public_html/sendfriend.php on line 20

Here's my code again:

<?php
$name = $_POST['name'];
$recipient1 = $_POST['recipient1'];
$recipient2 .= $_POST['recipient2'];
$recipient3 .= $_POST['recipient3'];
$recipient4 .= $_POST['recipient4'];
$recipient5 .= $_POST['recipient5'];
if (!$_POST['optionalmessage'])
{
$optionalmessage = "";
} else {
$optionalmessage = "A personal message from your friend: /n $_POST['optionalmessage']";
}
$URL = $_POST['URL'};
// initialize a variable to 
   // put any errors we encounter into an array
   $errors = array();
     // check to see if a name was entered
   if (!$_POST['name'])
      // if not, add that error to our array
      $errors[] = "Name is required";
      // check to see if 1 recipient was entered
      if ($_POST['recipient1'])
      //if not add that error
      $errors[] = "At least one recipient is required";
               // if there are any errors, display them
   if (count($errors)>0){
      echo "<strong>ERROR:<br>\n";
      foreach($errors as $err)
        echo "$err<br>\n";
   } else {
// no errors, so we build our message
// Sends form
$to = $recipient1;
$to .= $recipient2;
$to .= $recipient3;
$to .= $recipient4;
$to .= $recipient5;
$subject = "$name thinks you should check out this site!";
$msg = "$name thought you might be interested in this page <a href='$URL'</a>' 
$optionalmessage";
if (mail($to, $subject, $msg, "From: Morning Glory Guesthouse Bed and Breakfast"))
         echo "Thanks for your message!  Please note, that sometimes errors may occur and we may not receive your email.  If you do not receive a prompt reply, please send an email to <email removed>.  Please state that you filled out the form, but did not receive a reply";
      else
         echo "An unknown error occurred.  Please try again.  If you receive this error multiple times, please email the webmaster at <email removed>";
   }
?>
Thank you guys for your help and patience!

P.S. Businessman, that would be great if you could write a script to get the referring pages title! You're very kind, and I greatly appreciate your help! :)

EDIT: Hehehe, I copied and pasted some of that from an email form script that I have on that site... that's why it echos thanks for your message if you don't recieve a prompt reply please send an email to blah blah blah etc. :P Obviously that will be changed some.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users