PHP Doku:: Setzt URL-Rewrite-Variablen - function.output-add-rewrite-var.html

Verlauf / Chronik / History: (6) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenAusgabepufferungOutput-Control-Funktionenoutput_add_rewrite_var

Ein Service von Reinhard Neidl - Webprogrammierung.

Output-Control-Funktionen

<<ob_start

output_reset_rewrite_vars>>

output_add_rewrite_var

(PHP 4 >= 4.3.0, PHP 5)

output_add_rewrite_var Setzt URL-Rewrite-Variablen

Beschreibung

bool output_add_rewrite_var ( string $name , string $value )

Diese Funktion fügt ein Name/Wert-Paar zum URL Rewrite Mechanismus hinzu. Name und Wert werden in der gleichen Art wie die Session-ID als GET-Parameter zu URLs und als versteckte Felder zu Formularen hinzugefügt wenn das transparente URL-Rewriting mit session.use_trans_sid aktiviert ist. Bitte beachten Sie das nur relative URLs, nicht aber absolute wie http://example.com/... automatisch erweitert werden.

Diese Funktion wird auch über den php.ini Parameter url_rewriter.tags gesteuert.

Hinweis: Ein Aufruf dieser Funktion aktiviert automatisch die Ausgabepufferung falls sie nicht schon aktiv ist.

Beispiel #1 output_add_rewrite_var() Beispiel

<?php
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());
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

<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
)

Siehe auch output_reset_rewrite_vars(), ob_flush() und ob_list_handlers().


4 BenutzerBeiträge:
- Beiträge aktualisieren...
Anonymous
20.10.2008 18:16
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', '&');
?>
neo at nowhere dot com
26.03.2008 19:51
As a small side note, when there are values in the output_add_rewrite_var() function, these values are applied to all dynamic addresses (with in the limits posted above), including addresses that already have that variable set.

Example:

<?
output_add_rewrite_var
("page", "admin");
echo
'<a href="?a=signup&page=home">Signup</a>';
?>

The above will output the following:

<a href="?a=signup&page=home&page=admin">Signup</a>

However, this is easy to get around, using output buffering inside of output buffering. Because in my case, I couldn't remove the rewrite variable, as I have no idea if the next address would need it or not.
Niko
24.02.2008 10:58
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>
Bruce
6.09.2007 16:54
Just to clarify...

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



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)