Code: Select all
<?php
class CUrl {
var $anchor;
var $param = array();
var $script_name;
var $protocol;
var $separator;
var $add_sid;
function CUrl() {
$this->script_name = $_SERVER[SCRIPT_NAME];
$this->param = $_GET;
$this->separator = '&';
$this->add_sid = true;
if($this->add_sid) $this->setParam(session_name(), session_id());
}
function setParam($name='',$val='') {
$this->param[$name] = $val;
}
function setAnchor($anchor='') {
$this->anchor = $anchor;
}
function dropParam($name='') {
unset($this->param[$name]);
}
function setScriptName($script_name) {
$this->script_name = $script_name;
}
function getUrl() {
return $_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];
}
function makeUrl() {
$res = $this->script_name;
if (count($this->param)>0)
$res .= '?';
$tarr = array();
foreach ($this->param as $key=>$val) {
$tarr[] = $key.'='.(urlencode($val));
}
$res .= implode($this->separator,$tarr);
return $res;
}
function makeLink($name='',$title='', $class='') {
echo '<a href="'.$this->makeUrl().'#'.$this->anchor.'"';
if($title) echo ' title="'.$title.'"';
if($class) echo ' class="'.$class.'"';
echo '>'.$name.'</a> ';
}
}// end class
?>