Sending variable using HTTP_REFERER

Discussion in 'PHP' started by Alam, Dec 27, 2007.

  1. #1
    main.php
    ------------------


    <?
    echo $msg;
    ?>



    <form action="process.php" method="post">
    <input type="text" name="name">
    <input type="hidden" name="action" value="vua">
    <input type="submit" value="submit">
    </form>



    process.php
    ----------------------

    <?

    if($action=="vua")
    {
    $msg="Hello $name";
    header("Location: ".$HTTP_REFERER);
    exit();
    }

    ?>


    Hi,

    I have created above php files. user will type his/her name in input box and clicking on submit button, process.php will check and send a value (name) in $msg variable and redirect to referer page. Then referer page will show the value of $msg

    But this script is not working:((

    Please help me :)
     
    Alam, Dec 27, 2007 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Why not do everything from one file? Try this:

    <?
    
    if ( isset( $_POST['name'] )
    {
        echo 'hello' . htmlentities( $_POST['name'] ) . '<br />';
    }
    ?>
    
    <form action="process.php" method="post">
    <input type="text" name="name">
    <input type="hidden" name="action" value="vua">
    <input type="submit" value="submit">
    </form>
    PHP:
    Brew
     
    Brewster, Dec 27, 2007 IP
    Alam and basketmen like this.
  3. nks

    nks Well-Known Member

    Messages:
    1,602
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Hi Brewster, I think you forgot the word 'php' beside the "<?" sign.

    i.e.
     
    nks, Dec 27, 2007 IP
  4. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #4
    oops, you're right. I must have missed that when copying the original code. Thanks for pointing it out.

    Brew
     
    Brewster, Dec 27, 2007 IP
  5. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #5
    Thanks for reply :)

    But I need the process.php with its code as the same. :(

    Please help :)
     
    Alam, Dec 27, 2007 IP
  6. coches

    coches Peon

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if($action=="vua")
    {
    $msg="Hello $name";
    header("Location: ".$HTTP_REFERER);
    exit();
    }

    you should read about globals

    if($_POST['action']=="vua")
    {
    $msg="Hello $_POST['name']";
    header("Location: ".$_SERVER['HTTP_REFERER']);
    exit();
    }
     
    coches, Dec 27, 2007 IP
    Alam likes this.
  7. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #7


    I have used


    if($_POST['action']=="vua")
    {
    $msg="Hello ".$_POST['name'];
    header("Location: ".$_SERVER['HTTP_REFERER']);
    exit();
    }

    Not responsing. :(

    msg.php is not getting the value of $msg

    By the by, how process.php will send the value of $msg ?????
     
    Alam, Dec 27, 2007 IP
  8. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #8
    I need to send a value from process.php to msg.php but i need to use HTTP_REFERER :(
     
    Alam, Dec 27, 2007 IP
  9. gary.viray

    gary.viray Banned

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    HTTP_REFERER doesn't work with other browsers.
     
    gary.viray, Dec 27, 2007 IP
  10. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #10
    What exactly do you want to achieve?

    You could use something like this, but it just doesn't make sense why would you want it this way:
    In main.php replace this:
    
    <?
    echo $msg;
    ?>
    
    PHP:
    with this
    
    <?
    if (isset($_GET['message'])) echo $_GET['message']; 
    ?>
    
    PHP:
    process.php should contain this code (i took the code version from coches):
    
    if($_POST['action']=="vua")
    {
     $msg="Hello ".$_POST['name'];
     header("Location: ".$_SERVER['HTTP_REFERER']."?message=".$msg);
     exit();
    }
    
    PHP:
    Didn't check the code for errors and vulnerabilites, but just try it out and explain what exactly you want...
     
    hogan_h, Dec 27, 2007 IP
    Alam likes this.
  11. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #11
    
    
    if($_POST['action']=="vua")
    {
    $msg="Hello ".$_POST['name'];
    echo $_SERVER['HTTP_REFERER'];
    header("Location: ".$_SERVER['HTTP_REFERER']);
    exit();
    }
    
    
    PHP:
    What do you get?

    Peace,
     
    Barti1987, Dec 27, 2007 IP
  12. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #12
    it is working :)

    Thanks
     
    Alam, Dec 27, 2007 IP
    hogan_h likes this.
  13. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #13
    Sessions would work fine aswell.
     
    HuggyStudios, Dec 27, 2007 IP
    Alam likes this.
  14. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #14
    Yes, :)

    I have write the scripts like below and working very well as my requirement :D

    special thanks and repu added :)


    msg.php
    -------------

    <?
    session_start();
    session_register("msg");

    echo $msg;
    ?>



    <form action="process.php" method="post">
    <input type="text" name="name">
    <input type="hidden" name="action" value="vua">
    <input type="submit" value="submit">
    </form>


    process.php
    -------------------

    <?
    session_start();
    session_register("msg");

    if($_POST['action']=="vua")
    {
    $msg="Hello ".$_POST['name'];
    header("Location: msg.php");
    exit();
    }

    ?>
     
    Alam, Dec 27, 2007 IP
  15. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #15
    Thanks for the nice solution. Hope it will help me solve my problem.

    Rep addedd :D
     
    srobona, Dec 28, 2007 IP
    Alam likes this.
  16. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #16
    welcome @ srobona :)

    Thanks for repu ;)
     
    Alam, Dec 29, 2007 IP
    srobona likes this.
  17. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #17
    You can use the global $_SESSION when you use sessions, which i prefer to do.
     
    HuggyStudios, Dec 29, 2007 IP
  18. Alam

    Alam Active Member

    Messages:
    316
    Likes Received:
    91
    Best Answers:
    0
    Trophy Points:
    68
    #18

    Thanks for the better solution :)
     
    Alam, Dec 29, 2007 IP