http://rancidmoose.unitedti.org/forum/blog.php is working great and can even do stuff like this:

http://rancidmoose.unitedti.org/forum/blog.php?year=2006&month=05&num=01

however my problem is when in the redirect portion of my blogger template.

if you visit http://rancidmoose.unitedti.org/forum/blog/ it is supposed to redirect you to http://rancidmoose.unitedti.org/forum/blog.php and otherwise it takes the archive page url and parses that, then redirects to the corresponding blog.php url.

click around and see what happens.


here's my code:

Code:
<?php
    if(defined('IN_BLOG')){
      echo('<!--- including "' . $incstr . '"---><!--- --->');
    } else{
      $url = $_SERVER['PATH_INFO'];
      if(FALSE == strpos($url,'index.php')){
          $i = strpos($url, 'blog/') + 5;
          $i2 = strpos($url, '_',$i);
          $year = substr($url,$i, $i2-$i);
          $i = $i2 + 1;
          $i2 = strpos($url,'_',$i);
          $month = substr($url,$i, $i2-$i);
          $i = $i2 + 1;
          $i2 = strpos($url,'_',$i);
          $num = substr($url,$i, $i2-$i);
          $url = '../blog.php?year=' . $year . '&month=' . $month . '&num=' . $num;
      } else{
        $url = '../blog.php';
      }
      header('Location:'.$url);
    }

 ?>
Dunno if I'm just retarded or something at 1:45am, but I'm not seeing the phpBB template wrappers anywhere there.
Cool I haven't included those yet. Right now Im working on forcing it to redirect to the equivalent page in blog.php. The problem is in my url parsing.

What I want to grab from the url:
http://rancidmoose.unitedti.org/forum/blog/2006_04_01_rancidmoose_archive.php#114530708321804086 should be converted to http://rancidmoose.unitedti.org/forum/blog.php?year=2006&month=04&num=01

What it is grabbing:
http://rancidmoose.unitedti.org/forum/blog/2006_04_01_rancidmoose_archive.php#114530708321804086 is being converted to http://rancidmoose.unitedti.org/forum/blog.php?year=&month=&num=#114530708321804086
...can't you just have your server redirect blog/ to blog.php rather than a PHP script doing it? (like from CPanel or something - there are redirect setups there, use it)

anywho, you are now my 2nd enemy, right behind jpez - you don't need or deserve a blog either Mad (although yours isn't QUITE as bad as you actually make stuff - but still totally worthless)
no, since that particular server doesn't allow .htaccess and I want to release this as a mod. The most important reason is that blog.php has to know which post to show.

Code:
<?php
$url = $_SERVER['url']; //not a real variable!!! I don't remember the env var
preg_replace('/\/(\d+)\_(\d+)\_(\d+)\_([A-Za-z0-9\.\#\_\-\~]+)$/',"?year=$1&month=$2&day=$3",$url); //this is actual regex
header("Location: ".$url);
?>
heh. thanks....now I need to learn to use regex.
No you don't, just use what I made for you. Smile
for future programs.... Rolling Eyes silly Kerm....

[edit]
your script doesn't seem to be working either....its just stripping fragment data from the end and going into an infinite redirect to itself instead of redirecting to blog.php.

back to my version.
Oh, I forgot to mention to put a preg_match to check whether it had already done the redirect...my bad. Very Happy

Edit: WAIT! no, just add $url = before the preg_replace.
still doesn't work.

Im not entirely sure, since I dont really know what the regex is doing, but it looks like it isn't switching from /forum/blog/somefilehere to /forum/blog.php.

[edit]
my way is working now. Rolling Eyes I was using the wrong environment variable.
Lemme explain:


Code:
preg_replace('/\/(\d+)\_(\d+)\_(\d+)\_([A-Za-z0-9\.\#\_\-\~]+)$/',"?year=$1&month=$2&day=$3",$url);


Alrighty. The first part is the search, second is replace, and third is var. All but the first are self explanatory, so here goes. You must always start with '/ and end with /' to tell PHP it's a regex expression. the (\d+) match one or more digits characters, and each parethetical set is stored sequentially as $1, $2, $3, etc. Sets of characters in [] match one or more of any character in the brackets; you can also put character classes like \d \w \s etc in.
so let me see....

/2006_05_01_rancidmoose_archive.php would become
?year=2006&month=05&num=01?
elfprince13 wrote:
so let me see....

/2006_05_01_rancidmoose_archive.php would become
?year=2006&month=05&num=01?


Almost. Get rid of that initial '/' - that just tells the PHP parser we're giving it a regex expression.
thats why it wasn't working.

woot woot.

/2006_05_01_rancidmoose_archive.php should become

.php?year=2006&month=05&num=01
So is it working now then...
well, it is working, but Im not using the regex (yet).
Oh, ok. How are you doing it then
my originial code had only one wrong server variable.

Code:

<?php
    if(defined('IN_BLOG')){
      echo('<!--- including "' . $incstr . '"---><!--- --->');
    } else{
      $url = $_SERVER['SCRIPT_PATH'];
      if(FALSE == strpos($url,'index.php')){
          $I = strpos($url, 'blog/') + 5;
          $i2 = strpos($url, '_',$I);
          $year = substr($url,$I, $i2-$I);
          $I = $i2 + 1;
          $i2 = strpos($url,'_',$I);
          $month = substr($url,$I, $i2-$I);
          $I = $i2 + 1;
          $i2 = strpos($url,'_',$I);
          $num = substr($url,$I, $i2-$I);
          $url = '../blog.php?year=' . $year . '&month=' . $month . '&num=' . $num;
      } else{
        $url = '../blog.php';
      }
      header('Location:'.$url);
    }

 ?>
This whole thing:

Code:
          $I = strpos($url, 'blog/') + 5;
          $i2 = strpos($url, '_',$I);
          $year = substr($url,$I, $i2-$I);
          $I = $i2 + 1;
          $i2 = strpos($url,'_',$I);
          $month = substr($url,$I, $i2-$I);
          $I = $i2 + 1;
          $i2 = strpos($url,'_',$I);
          $num = substr($url,$I, $i2-$I);
          $url = '../blog.php?year=' . $year . '&month=' . $month . '&num=' . $num;
is my one line of regex. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement