#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0

    passing the url from HTML page to a php


    I'm trying to build a "share this page" script in php. I'm trying to pass the full URL of page one (html page) to page two that has a form for sharing page one.


    I've tried using this script to capture the referering URL:

    $url = $_SERVER['HTTP_REFERER'];
    This script correctly captures the url from page one. Example:

    http://www.whatever.com/dah/pageOne.html

    But it doesn't end up in the email because...

    The form on page two is submitted to itself.

    When the form is submitted the variable $url then becomes the url of page two. The URL of page two is what ends up in the email.
    Example:

    http:www.whatever.com/dah/pageTwo.php

    How do I capture the the url of page one on page two and so I can put it in the email.

    Here's a bit more of the script from page two:
    $origin=$_SERVER["HTTP_REFERER"];
    $Message = "HELLO\n $sname, thought you would be interested in this article at rwyouth.com \n $sharedFile \n $comment";
    $ToSubject = "$rname, I found this great article at RWYouth.com";
    echo "<span class=\"boldorange\">Your Email Was Sent!</span>";
    mail($rname." <".$remail.">",$ToSubject, $Message, "From: ".$sname." <".$semail.">");
    I'd be much appreciative is anyone would shed some light on my little problem.

    Thanks,

    Newbie in Wisconsin
    Last edited by lordorkus; January 18th, 2004 at 07:29 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Leeds, UK
    Posts
    171
    Rep Power
    18
    The problem is obviously because when page 2 submits to itself it is going to be the referer.

    One way round this is to only work out $url the first time page 2 is loaded and put it in a hidden field on your form on page 2.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0
    Thanks for the quick reply emilyb,

    what do you mean by "work out $url". How do I keep it from changing when page 2 is submitted?

    I added the hidden field:

    <input type="hidden" name="link" value="<?= $url ?>">

    But I still got the wrong link in the email.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    84
    Rep Power
    15
    If the variable gets boogered up by the form submitting to itself then don't do that. Submit the form to another page and carry the url over in another variable. It might be less 'elegant' but it will work. You can work out the fancy stuff later.
    Gordon
    ======
    ECNCweather.com
    Where are we going and why am I in this handbasket?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0

    okay


    Does any one know how to prevent the variable "from getting boogered" or in other words from changing when it is sent to the next page?

    How do I get the variable to capture the referer and then not change when the page is submitted to itself?
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    5
    Rep Power
    0
    Have you tried:

    on pagetwo:
    PHP Code:
    if (!(isset($_POST['link']))){
    $url $_SERVER['HTTP_REFERER'];
    // insert form body here for user to input the email address(es)
    //don't forget to include:
    echo "<input type=\"hidden\" name=\"link\" value=\"" $url "\">";
    } else if (isset(
    $_POST['link'])){
    $url $_POST['link'];
    //send the mail!!!!!

    This should work. Does this help?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    84
    Rep Power
    15
    There's a function that let's PHP determine what page it's running on.... something like PHPSELF().

    You could try something along these lines:
    PHP Code:
    $lastpage $_SERVER['HTTP_REFERER'];
    $thispage PHPSELF(); #or whatever the function is
    if $thispage $lastpage
    {
    #do nothing
    }
    else
    {
    $url $lastpage

    That's not gonna be all technically correct (lunch break is running out) but hopefully ya get the idea. I think Hundal's suggestion does a similar workaround, just differently.
    Gordon
    ======
    ECNCweather.com
    Where are we going and why am I in this handbasket?
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0

    Got the Variable to Stick on Page two but...


    Okay I've been able to pass the URL from the HTML page to the php page using a simple Java Script like this:
    <form action="SendArticle2.php" method="post" name="alice">
    <input type="SUBMIT" value="Submit">
    <script language="JavaScript">var theSpot=document.URL; document.write("<input type='hidden' name='place' value='"+theSpot+"'>"); document.write(theSpot);</script>
    </form>

    I'm able to get "theSpot" to print on page two with this script:
    PHP Code:
    $whatEver $_POST['place'];
    $monkey $whatEver;
    echo 
    "$monkey"
    Under that is this :


    PHP Code:
    if (isset ($_POST['submit'];)) {
        foreach(
    $_POST as $key=>$value) {
         $
    $key $value;
        }
        
        
    $valid $rn checkLength($rname130);
        
    $rem checkEmail($remail);
        
    $valid $valid && $rem;
        
    $sn checkLength($sname130);
        
    $valid $valid && $sn;
        
    $sem checkEmail($semail);
        
    $valid $valid && $sem;
        if (
    $valid) {
        
       
    sendArticle();
        
            
        }
    } else {
        
    $rn $sn $sem =  $rem =  TRUE;
        
    $rname $sname $semail $remail;

    Last edited by lordorkus; January 20th, 2004 at 04:10 PM.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0

    This thing's broke


    And finally the mail function. As you can see I've declared global variables. But $monkey will not show up in my email...



    PHP Code:
    function sendArticle(){

    global 
    $whatEver$monkey$rname$remail$sname$semail$comment;
        
        
    $origin=$_SERVER["HTTP_REFERER"];
            
    $Message "Hello,\n$sname, thought you would be interested in this article at rwyouth.com \n\n $monkey \n\n Comment: $comment";
            
    $ToSubject "$rname, I found this great article at RWYouth.com.";
             echo 
    "<span class=\"boldblack\">Your Email Was Sent! $monkey <br> Send Another?</span>";
             echo 
    "$monkey";
             
    mail($rname." <".$remail.">",$ToSubject$Message"From: ".$sname." <".$semail.">");


    Last edited by lordorkus; January 20th, 2004 at 04:21 PM.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    7
    Rep Power
    0

    This board is not responding well to my browser...Safari SUCKS


    Okay well anyway... Does anybody have any idea why $monkey will print on page two but not go into the email?


    Thanks


    NEWBIE...
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    5
    Rep Power
    0
    Does:

    PHP Code:
    echo "Before function: " $monkey "<BR>\n";
    sendArticle($monkey);
    echo 
    "After function : " $monkey "<BR>\n"
    and sendArticle($url) will be:

    PHP Code:
    function sendArticle($url){
      echo 
    "Inside function: " $url "<BR>\n";
      
    //comment out the rest

    what does this produce? does it display all the 3 values right?

IMN logo majestic logo threadwatch logo seochat tools logo