For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > June 2006 > output_add_rewrite_var() with other protocol/server ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author output_add_rewrite_var() with other protocol/server ?
broutard@gmail.com

2006-06-17, 8:04 am

Hi,

I try to use output_add_rewrite_var() function like this :

<?php
output_add_rewrite_var('id', 'test');
?>
<a href="file.php">without domain</a><br>
<a href="http://www.mydomain.com">with my domain</a><br>
<a href="http://www.mydomain.com">with my https domain</a><br>
<a href="http://www.google.com/">other domain</a><br>


---- the result is :

<a href="file.php?id=test">without domain</a><br>
<a href="http://www.mydomain.com">with my domain</a><br>
<a href="https://www.mydomain.com">with my https domain</a><br>
<a href="http://www.google.com">other domain</a><br>

------

If I specifie the domain, it seems don't work.
How can I use output_add_rewrite_var() in a link to my https server ?

Please help me.


Best regards.

Janwillem Borleffs

2006-06-17, 8:04 am

broutard@gmail.com wrote:
> If I specifie the domain, it seems don't work.
> How can I use output_add_rewrite_var() in a link to my https server ?
>


You can't, unless running it on the https domain itself. The reason for this
is that it obeys the same rules which apply to the url_rewriter.tags php.ini
directive and since sessions aren't cross-domain by default, this won't
work.

For non-ssl domains, you could omit the protocol, causing most browsers to
prefix it automatically:

<a href="//www.mydomain.com/index.php">with my domain</a>

For ssl domains, the only solution is to write your own replacement
function, e.g.:

<?php

function rewrite_tags($content) {
global $output_add_rewrite_vars;
foreach ($output_add_rewrite_vars as $k => $v) {
$content = preg_replace(
'/href="([^"]+)"/',
"href=\"$1?$k=$v\"",
$content
);
}
return $content;
}
ob_start('rewrite_tags');
$output_add_rewrite_vars = array('id' => 'test');

?>
<a href="https://www.mydomain.com/">with my domain</a><br>


JW



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com