| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| NamePros Regular | Needed: 'Email a friend' php code with . . . I need a php code like the one here: http://www.ibdjohn.com/sendurl/ BUT I need it to automatically read the name of the page it is on so I can paste it on 40+ pages without having to manually alter the code to point the email to the URL. Is this possible? |
| |
| | #2 (permalink) |
| Senior Member | You could get the url of the current page with some PHP code like : Code: <? echo $_SERVER['PHP_SELF']?> Code: <script> document.write(document.title); </script> Hope that helps, David. |
| |
| | #3 (permalink) | ||
| NamePros Regular | So I just take the first lot of code Quote:
Quote:
I don't know a lot about php so how does this work? <input type=hidden name="urlis" value=<? echo $_SERVER['PHP_SELF']?> Or where else does this code go ???????? | ||
| |
| | #4 (permalink) |
| Senior Member | cjcjcj, Like this: <input type=hidden name="urlis" value="http://www.yourdomainname/yourpagename"> Replace the bold so it could be: <input type=hidden name="urlis" value="<? $page_url = 'http://www.yourdomainname.com'; // your domain name here $page_url .= $_SERVER['PHP_SELF']; echo $page_url; ?>"> just edit the domain name.. |
| |
| | #5 (permalink) |
| NamePros Regular | A little confused. I wanted to get a code where I wouldn't need to enter the domain name on each page where I put the code. Instead, the code would read it from somewhere and adapt the email that is sent out to the 'friend'. What does the above code do? |
| |
| | #6 (permalink) |
| Senior Member | Ok well, I found this premade code for you, I think it does what you look for. <input type=hidden name="urlis" value=" <? $_SERVER['FULL_URL'] = 'http'; if($_SERVER['HTTPS']=='on'){$_SERVER['FULL_URL'] .= 's';} $_SERVER['FULL_URL'] .= '://'; if($_SERVER['SERVER_PORT']!='80') $_SERVER['FULL_URL'] .= $_SERVER['HTTP_HOST'].':'.$_SERVER ['SERVER_PORT'].$_SERVER['SCRIPT_NAME']; else $_SERVER['FULL_URL'] .= $_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; if($_SERVER['QUERY_STRING']>' '){$_SERVER['FULL_URL'] .= '?'.$_SERVER['QUERY_STRING'];} echo $_SERVER['FULL_URL']; ?> "> It should output the full url in the value. Copy the code where you want to use it, and you do not need to edit anything. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tutorial: Getting started with PHP (The Basics) | deadserious | Webmaster Tutorials | 60 | 11-17-2007 11:35 AM |
| HOWTO: Protect Your Email | DarkDevil | Webmaster Tutorials | 12 | 08-17-2004 08:49 PM |