Results 1 to 5 of 5

Thread: Sending POST requests with links, howto??

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sending POST requests with links, howto??

    Hello again,

    I wanted to know if I could pass POST/REQUEST variables through links just like gets?? I just wanted to know because I have seen this kind of effect(in which every process occurs in one PHP page and you can't even see the ?... things in the URL). Does anyone have any idea how this can be done?? Any help would be greatly appreciated. Thanks.

  2. #2
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If I understood well what you want, offcource you CAN. Say that you have a post variable $name = $_POST['name']. OK, you just add that in the link as shown:
    Code:
    <?
    $name = $_POST['name'];
    ?>
    <html>........
    <body>
    <a href="somewhere.php?name=$name">LINK</a>
    </body>
    </html>
    Note: The underlined "name" is a value that you set it as you like. But then when accessing the variable, you should use the name you set.(see example)

    Then, from the file you linked you can access the variable as you would access it if it was GET one. E.g.:
    Continuing the previous example:
    Code:
    <?
    $name = $_GET['name'];
    ?>
    Note: If I'd given the variables name (underlined one in the first example) instead of the "name" value the "user" one, I should write: $name = $_GET['user'];

    Hope I helped!!!

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello Costas,

    You almost got what I wanted to do but I know how to do that with GET requests and I meant POST requests. Anyways thanks for your help.

    I meant something like this:

    PHP Code:
    <a href="some.php?method=post">test link</a
    some.php:
    PHP Code:
    <?php
    if(isset($_POST['method'])){
    echo 
    'method used: '.$_POST['method'];
    }
    ?>
    But I want to get that data(value of method) without making it appear in the URL. Even when the user clicks the link the URL must be something like this: some.php

    Now that's what I wanted to do. If you want a demo of this then you can see the installation script in a CMS called bitweaver, all the installation pages are displayed under one URL that is install.php and the url doesn't change to install.php?somekey=somevalue

    Is this done with session variables?? If yes how to??

    If you know how to do that with POST then please let me know.


    Hope it makes sense.
    Last edited by shachi; 08-27-2006 at 12:49 PM.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    all the installation pages are displayed under one URL that is install.php and the url doesn't change to install.php?somekey=somevalue

    Is this done with session variables?? If yes how to??
    Or an iframe.

    It's impossible to POST via a link, although you can link to a PHP page that will perform a POST and display the output. XMLHttpRequest can do it too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    I wanted to know if I could pass POST/REQUEST variables through links just like gets??
    No.

    Does anyone have any idea how this can be done??
    Use a form and style the submit button like a link (remove the border, change the background colour, etc.).

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •