|
Posted by David Haynes on 05/30/06 13:42
pepito3@gmail.com wrote:
>> I think you need to read up on how a browser and web server interact
>> some more. This is pretty basic stuff but you seem to be missing some
>> key concepts based upon the type of questions you are asking.
>
>> The 'list_product.php' may be *any* valid url string.
>> That includes:
>> URLs that are not absolute.
>> Different urls based upon code.
>> URLS that include get operators.
>> URLS that are mod_mapped.
>
> My question is much simpler (and I understand how a http server works),
> maybe I didn't explain myself very well:
>
> If I used redirect(X) I would have to store X in $_POST or $_SESSION
> arrays so that add_product.php can get that X. That's something I can't
> do as an action performed when the user clicks on a link. So how can I
> do that?
>
The only way to pass data via a link is to use a GET method. This will
pass data from the browser to the web server.
Why are you restricted to a link? With some simple css code, you can
make a form look like a link and then you would have POST methods
available to you.
Regardless of whether you use POST or GET from the browser to the
server, you will have to use SESSION to send the data to another page.
So, if you are going to use GET on the links:
[foo1.php]
<?php
session_start();
$foo = isset($_SESSION['foo']) ? $_SESSION['foo'] : '';
$fred = isset($_SESSION['fred']) ? $_SESSION['fred'] : '';
....
// create a dynamic url to the foo2 page based on whether
// any of foo or fred is set
$url = "foo2.php";
// NOTE: if there are a big set of values, this could be
// done in a foreach loop.
$first = true;
if( $foo != '' ) {
$url .= '?foo='.$foo;
$first = false;
}
if( $fred != '' ) {
if( $first ) $url .= '?fred='.$fred;
else $url .= '&fred='.fred;
}
?>
....
<a href="<?php echo $url;?>">Link</a>
....
[foo2.php]
<?php
session_start();
if( isset($_GET['foo']) ) $_SESSION['foo'] = $_GET['foo'];
if( isset($_GET['fred'] ) $_SESSION['fred'] = $_GET['fred'];
....
session_write_close();
header("location: foo1.php");
?>
If this doesn't answer your issue, perhaps you could restate it with a
small example since I am obviously not understanding your problem.
-david-
[Back to original message]
|