Jump to content


How To Find The Page Url?


3 replies to this topic

#1 Pelleke

    Etomite Forum Fan

  • Member
  • Pip
  • 58 posts

Posted 09 February 2006 - 11:45 AM

Hello!

I got a problem... I am writing a snippet which sometimes submits a form to itself, and links to itself with certain additional GET-variables. Now this is my thing: at a certain moment my page url looks i.e. like this:
http://www.domain.com/index.php?id=14&var=...astvar=fooagain
And now in that document I have to make a link to
http://www.domain.com/index.php?id=14&diff...=ofdifferentuse
Now I am planning to implement a way to do this by taking $_SERVER['PHP_SELF'] and adding a '?' and then parse $_SERVER['QUERY_STRING'] in a certain way so that it will only hold the id-variable. But I think this is not the most secure way to handle this, and it may be buggy in some cases. So my question is: is there a way (read: variable-value) which gives me just the full URL of a page? (Like $etomite->pageurl or so?)

Edited by pelleke, 09 February 2006 - 11:54 AM.


#2 Pelleke

    Etomite Forum Fan

  • Member
  • Pip
  • 58 posts

Posted 09 February 2006 - 12:04 PM

OK people, figured it out myself.

$url=$etomite->makeUrl($etomite->documentIdentifier);
$url.= substr($url,'?') ? '&' : '?';

gives in $url something like
http://www.domain.com/id=28&


#3 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 09 February 2006 - 01:44 PM

pelleke, on Feb 9 2006, 12:04 PM, said:

OK people, figured it out myself.

$url=$etomite->makeUrl($etomite->documentIdentifier);
$url.= substr($url,'?') ? '&' : '?';

gives in $url something like
http://www.domain.com/id=28&

makeURL takes three parameters, id, unused, parameterstring
where parameterstring is expected to have a leading '?' (ie "?name=value&name2=value2")
so you could use
$url=$etomite->makeUrl($etomite->documentIdentifier, 0, "?name=value&name2=value2" );

However, in the current RTM release, I don't think it gets it right in all cases (the "?" needs replacing by "&" in some cases), but I've sent Ralph a patch for testing.

Edited by mikef, 09 February 2006 - 01:46 PM.


#4 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 09 February 2006 - 02:38 PM

Here is the makeURL() function as it is implemented as of RTMb... As mike pointed out, the alias field is no longer required as it is automatically used based on configuration settings... You can also send a NULL ("") in place of the zero in the alias field but whatever is sent gets ignored anyway so it doesn't make much difference...
 function makeUrl($id, $alias=0, $args='') {
  // Modified by mikef
  // returns a properly formatted URL as of 0.6.1 Final
  // $id is a valid document id
  // $alias is now an unused parameter because it is now calculated based on $id
  // $args is a URL compliant text string of $_GET key=value pairs
  // Example: makeURL(45,'','?cms=Etomite')
  // ToDo: add conditional code to create $args from a $key=>$value array
    global $ETOMITE_PAGE_BASE;
    if(!is_numeric($id)) {
      $this->messageQuit("`$id` is not numeric and may not be passed to makeUrl()");
    }
    $baseURL=$ETOMITE_PAGE_BASE['www'];
    if($this->config['friendly_alias_urls']==1 && isset($this->aliases[$id])) {
      $url = $baseURL.$this->aliases[$id];
    } elseif($this->config['friendly_urls']==1) {
      $url = $baseURL.$this->config['friendly_url_prefix'].$id.$this->config['friendly_url_suffix'];
    } else {
      $url = $baseURL."index.php?id=$id";
    }
    if (strlen($args)&&strpos($url, "?")) $args="&".substr($args,1);
    return $url.$args;
  }






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users