1 (edited by nfl-forums 2004-10-12 19:17)

Topic: Forums using mod_rewrite

I had to do quite a bit of modifications, but I was able to get everything working (I think).

I'd love to hear some feedback on this.

http://forums.site-reference.com

NFL-Forums.com administrator

Re: Forums using mod_rewrite

Very nice. I can imaging it would have been a lot easier if all URL's were generated by a function instead of being hard-coded into the source. I.e. instead of putting post.php?tid=$tid&qid=$qid in the source, you would call e.g. pun_url('post.php', array('tid' => $tid, 'qid' => $qid)). That way, you could do all the mod_rewrite stuff in that function. I've thought about this ealier. Maybe I'll think something up for 1.2.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by Frank H 2004-10-12 20:40)

Re: Forums using mod_rewrite

perhaps just a variable that the function fetch with a global ... so people just write like this in the code

}
if($super_duper_mod)
{
  //set a get variable to be used
  $url_var['myid']=generate_random_user();

  //lots of other code
}

//lots of code

$url_var['id']=$fid;
echo '<form action="'.pun_url('post.php').'">'; //etc...



and the pun_url function


function pun_url($url='error.php')
{
  global $url_var;
  $first=true;

  foreach $url_var as $key=>$value
  {
    if($first)
    {
      $url .= '?' . $key . '=' . $value;
      $first=false;
    }else
      $url .= '&' . $key . '=' . $value;
  }
  return url;
}

or something similar ... (heh I wrote it as I anyway needed to write one, have thought about it for a while, but never got to rewriting my  little thing for it big_smile)

Re: Forums using mod_rewrite

oh, and that rewrite you've made seems to work fine ... nice work smile

Re: Forums using mod_rewrite

Thanks.

Yes, a function would make life quite a bit easier. smile  Its the second time going through things, so it took a little less time.  I did get hung up in one spot, however.  When you go to the last post, why is it formated as viewtopic.php?id=3#3?

NFL-Forums.com administrator

Re: Forums using mod_rewrite

there is a '<a name="'.$postid.'"></a>' at every post, and the # is a html indicator to jump to that named position ... so a #3 at the end means it will jump to the nametag that has the value 3 ....

<div><a name="23183"></a></div>

from the source of this page ... so if you put #23183 at the end of the current url, you will jump to that post

Re: Forums using mod_rewrite

Frank H: That is another solution, but I can't see what advantages it has. It requires two separate actions (add variables to the global array and call the function) instead of one.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Forums using mod_rewrite

Rickard wrote:

Frank H: That is another solution, but I can't see what advantages it has. It requires two separate actions (add variables to the global array and call the function) instead of one.

well ... it's possible to include get tags for mods in the small code snippets the mods use, instead of needing to modify a line in the original code(and therefore making muliple mods to clash) ... but, hmm... I just figured out that you don't always want to send the same get tags on every url tongue ... hmm... actually then your way is probably the best way to go ... or ... I'll probably extend the function alittle for me (also allowing an array in the function call)

Re: Forums using mod_rewrite

I still don't get it :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."