Boerboel649 Posted April 18, 2006 Share Posted April 18, 2006 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! Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 18, 2006 Share Posted April 18, 2006 Try this, my furry friend:[code]$current_url = 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];[/code] Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 19, 2006 Author Share Posted April 19, 2006 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)[code]<?phpecho "$_SERVER[HTTP_REFERER]";?>[/code]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.[code]<!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>[/code]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. :) Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 19, 2006 Author Share Posted April 19, 2006 Anybody? Why will it not display the HTTP referer, when the page is accessed through a Javascript popup window?Thanks! Quote Link to comment Share on other sites More sharing options...
ober Posted April 19, 2006 Share Posted April 19, 2006 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. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 20, 2006 Author Share Posted April 20, 2006 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! Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 20, 2006 Share Posted April 20, 2006 [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. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 23, 2006 Author Share Posted April 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 23, 2006 Share Posted April 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 23, 2006 Share Posted April 23, 2006 <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. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 23, 2006 Author Share Posted April 23, 2006 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!!!!! Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 23, 2006 Share Posted April 23, 2006 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. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 23, 2006 Author Share Posted April 23, 2006 Thanks for your help businessman. I think I'll just open it with _blank thing.Thanks so much for all of your help! Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 23, 2006 Share Posted April 23, 2006 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./ Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 23, 2006 Author Share Posted April 23, 2006 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! Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 23, 2006 Author Share Posted April 23, 2006 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.[code]if (!$_POST['optionalmessage'])$optionalmessage = "No personal message";} else {$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";[/code]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 18I'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:[code]<?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>"; }?> [/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 24, 2006 Share Posted April 24, 2006 not that I know ofthere 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. Quote Link to comment Share on other sites More sharing options...
Roberto Posted April 24, 2006 Share Posted April 24, 2006 [!--quoteo(post=367789:date=Apr 23 2006, 10:50 PM:name=Boerboel649)--][div class=\'quotetop\']QUOTE(Boerboel649 @ Apr 23 2006, 10:50 PM) [snapback]367789[/snapback][/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.[code]if (!$_POST['optionalmessage'])$optionalmessage = "No personal message";} else {$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";[/code][/quote]You are missing { and }ie[code]if (!$_POST['optionalmessage']){$optionalmessage = "No personal message";} else {$optionalmessage = " A personal message from your friend: /n $_POST['optionalmessage']";}[/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 24, 2006 Share Posted April 24, 2006 the guy who responded up there is right, that would probably be where you problem is. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 25, 2006 Author Share Posted April 25, 2006 Thanks Roberto, but now it's giving me this errorParse 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 20Here's my code again:[code]<?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>"; }?> [/code]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. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 27, 2006 Author Share Posted April 27, 2006 Anyone????? Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted April 30, 2006 Author Share Posted April 30, 2006 Please anyone! I've almost got this finished... I need some help on that syntax error. Normally I get great help on here, and I have until now. Would someone mind helping me out? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted April 30, 2006 Share Posted April 30, 2006 i don't have time now but if noone answers you my monday morning 9 eastern standard send me an email. I will fix it for you, or look at it and tell you how I am not working onthe weekends but I will do that for you on monday. or if I remember I will check the form and help you out. Quote Link to comment Share on other sites More sharing options...
Boerboel649 Posted May 1, 2006 Author Share Posted May 1, 2006 Thanks Businessman, I sent you an email. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.