PDA

View Full Version : Sending POST requests with links, howto??



shachi
08-27-2006, 07:32 AM
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.

costas
08-27-2006, 10:39 AM
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:


<?
$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:


<?
$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!!!

shachi
08-27-2006, 12:44 PM
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:



<a href="some.php?method=post">test link</a>

some.php:


<?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.

Twey
08-27-2006, 04:15 PM
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.

mwinter
08-28-2006, 10:47 AM
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