output_add_rewrite_var

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

output_add_rewrite_varAdd URL rewriter values

Descrizione

output_add_rewrite_var(string $name, string $value): bool

This function starts the 'URL-Rewriter' output buffer handler if it is not active, stores the name and value parameters, and when the buffer is flushed rewrites the URLs and forms based on the applicable ini settings. Subsequent calls to this function will store all additional name/value pairs until the handler is turned off.

When the output buffer is flushed (by calling ob_flush(), ob_end_flush(), ob_get_flush() or at the end of the script) the 'URL-Rewriter' handler adds the name/value pairs as query parameters to URLs in attributes of HTML tags and adds hidden fields to forms based on the values of the url_rewriter.tags and url_rewriter.hosts configuration directives.

Each name/value pair added to the 'URL-Rewriter' handler is added to the URLs and/or forms even if this results in duplicate URL query parameters or elements with the same name attributes.

Nota: Once the 'URL-Rewriter' handler has been turned off it cannot be started again.

Elenco dei parametri

name

The variable name.

value

The variable value.

Valori restituiti

Restituisce true in caso di successo, false in caso di fallimento.

Log delle modifiche

Versione Descrizione
7.1.0 As of PHP 7.1.0, a dedicated output buffer is used, url_rewriter.tags is used solely for output functions and url_rewriter.hosts is available. Prior to PHP 7.1.0, rewrite variables set by output_add_rewrite_var() shared an output buffer with transparent session id support (see session.trans_sid_tags).

Esempi

Example #1 output_add_rewrite_var() example

<?php
ini_set
('url_rewriter.tags', 'a=href,form=');

output_add_rewrite_var('var', 'value');

// some links
echo '<a href="file.php">link</a>
<a href="http://example.com">link2</a>'
;

// a form
echo '<form action="script.php" method="post">
<input type="text" name="var2" />
</form>'
;

print_r(ob_list_handlers());
?>

Il precedente esempio visualizzerĂ :

<a href="file.php?var=value">link</a>
<a href="http://example.com">link2</a>

<form action="script.php" method="post">
<input type="hidden" name="var" value="value" />
<input type="text" name="var2" />
</form>

Array
(
    [0] => URL-Rewriter
)

Vedere anche:

add a note add a note

User Contributed Notes 3 notes

up
1
Anonymous
16 years ago
For a completely valid XHTML document you have to set the arg_separator, use this before you use output-add-rewrite-var:

<?php
ini_set
('arg_separator.input', '&');
ini_set('arg_separator.output', '&');
?>
up
1
Niko
16 years ago
This function also adds a parameter to <input type="image"> fields!

Example:
This code:

<?
output_add_rewrite_var
('var','value');
echo
'<form action="" method="post">
        <input type="image" src="image.jpg" alt="go">
        </form>'
;
?>

will output something like this:

<form action="" method="post">
        <input type="hidden" name="var" value="value">
        <input type="image" src="image.jpg?var=value" alt="go">
        </form>
up
-6
Bruce
17 years ago
Just to clarify...

session.use_trans_sid does NOT need to be enabled in order for output_add_rewrite_var() to work.
To Top