944,111 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2796
  • PHP RSS
May 23rd, 2006
0

replace address - how to?

Expand Post »
Hi all,

I am wondering if anyone can help me with my problem.

I am in the process of starting a directory but I stumbled on a problem I would like to fix.

every link has an info link that redirects to an info page where more information can be found about that link.

The link is generated and I would like the "program" to generate a different link

the link I am getting now is http://www.fishingrolodex.com/fishing/link-14.html

where 14 is the ID of the link in my database

I however would like to change this to
http://www.fishingrolodex.com/fishing/<linktitle>-14.html

I tried to change this by changing link.ID into link.TITLE and however this works the link shows spaces and actually does not work at all lol

below I posted the codes of th pages I think are involved
Can somebode please look at this and try to help me out?
I would appreciate it very much

link.tpl (template file)
PHP Syntax (Toggle Plain Text)
  1. {strip}
  2. <table><tr>
  3. {* show page rank *}
  4. {if $smarty.const.SHOW_PAGERANK}
  5. <td>
  6. {include file="pagerank.tpl" pr=$link.PAGERANK}
  7. </td>
  8. {/if}
  9.  
  10. <td>
  11. <strong><a id="id_{$link.ID}" href="{$link.URL|escape|trim}" title="{$link.TITLE|escape|trim}"
  12. {* nofollow *}
  13. {if $link.NOFOLLOW or ($link.RECPR_VALID eq 0 and ($smarty.const.RECPR_NOFOLLOW eq 2 or
  14.  
  15. ($smarty.const.RECPR_NOFOLLOW eq 1 and $link.RECPR_REQUIRED eq 1)))} rel="nofollow"{/if}
  16. {if $smarty.const.ENABLE_BLANK} target="_blank"{/if}>
  17. {$link.TITLE|escape|trim}</a></strong> <span class="url">- {$link.URL|escape|trim}</span>
  18. <p>
  19. {$link.DESCRIPTION|escape|trim} -&nbsp;[<a href="{if !$smarty.const.ENABLE_REWRITE}
  20. {$smarty.const.DOC_ROOT}/detail.php?id={$link.ID}
  21. {else}
  22. {$smarty.const.DOC_ROOT}/fishing/link-{$link.ID}.html{/if}" title="{l}Read
  23.  
  24. more about{/l}: {$link.TITLE|escape|trim}">{l}Info{/l}</a>
  25.  
  26. {if $smarty.const.REQUIRE_REGISTERED_USER == 1 && !empty
  27.  
  28. ($regular_user_details) && ($regular_user_details.ID == $link.OWNER_ID)}
  29. ,&nbsp;<a href="{$smarty.const.DOC_ROOT}/submit.php?linkid={$link.ID}"
  30.  
  31. title="{l}Edit or Remove your link{/l}">{l}Review{/l}</a>
  32. {/if}
  33. ]
  34. </p>
  35. </td>
  36. </tr>
  37. </table>
  38. {/strip}
and the details.php

PHP Syntax (Toggle Plain Text)
  1. require_once 'init.php';
  2.  
  3. if (ENABLE_REWRITE == 1)
  4. {
  5. $dir = explode ("/", $_SERVER['REQUEST_URI']);
  6. $dir[sizeof ($dir)-1] = ereg_replace (".html$", "", $dir[sizeof ($dir)-1]);
  7. $dir[sizeof ($dir)-1] = ereg_replace ("^link-", "", $dir[sizeof ($dir)-1]);
  8. $id = $dir[sizeof ($dir)-1];
  9. }
  10. else
  11. $id = (!empty ($_REQUEST['id']) ? $_REQUEST['id'] : 0);
  12.  
  13.  
  14. if (!empty ($id))
  15. {
  16. if (!preg_match ("/^\d+$/", $id))
  17. $tpl->assign('error', "Invalid Link ID");
  18. else
  19. {
  20. $rdata = $db->GetRow("SELECT *, DATE_FORMAT(DATE_ADDED, '%M %d, %Y %r') AS `DAT` FROM `{$tables['link']['name']}` WHERE `ID` = ".$db->qstr($id));
  21. $data = array ();
  22. if (!$rdata)
  23. $tpl->assign('error', "Invalid ID [{$id}] passed - not found in database");
  24. else
  25. {
  26. $data['ID'] = $id;
  27. $data['TITLE'] = $rdata['TITLE'];
  28. $data['DESCRIPTION'] = $rdata['DESCRIPTION'];
  29. $data['URL'] = $rdata['URL'];
  30. $data['CATEGORY_ID'] = $rdata['CATEGORY_ID'];
  31. $data['OWNER_NAME'] = $rdata['OWNER_NAME'];
  32. $data['DATE_ADDED'] = $rdata['DAT'];
  33. $data['HITS'] = $rdata['HITS'];
  34. $data['PAGERANK'] = $rdata['PAGERANK'];
  35. $data['RATE_COUNT'] = $rdata['RATE_COUNT'];
  36. $data['RATE'] = $rdata['RATE'];
  37. $data['RATE_ENABLED'] = $rdata['RATE_ENABLED'];
  38. $cdata = $db->GetRow("SELECT `TITLE` AS `CATEGORY_TITLE`, `CACHE_TITLE`, `CACHE_URL` FROM `{$tables['category']['name']}` WHERE `ID` = '{$rdata['CATEGORY_ID']}' LIMIT 1");
  39.  
  40. $data['CATEGORY_TITLE'] = $cdata['CATEGORY_TITLE'];
  41. $data['CACHE_TITLE'] = $cdata['CACHE_TITLE'];
  42.  
  43. $site_url = (substr (SITE_URL, -1) != '/' ? SITE_URL.'/' : SITE_URL);
  44. $data['CATEGORY_URL'] = $site_url;
  45. $data['CATEGORY_URL'] .= (ENABLE_REWRITE == 1 ? trim ($cdata['CACHE_URL']) : 'index.php?c='.$data['CATEGORY_ID']);
  46.  
  47. $data['META_KEYWORDS'] = $rdata['META_KEYWORDS'];
  48. $data['META_DESCRIPTION'] = $rdata['META_DESCRIPTION'];
  49.  
  50. unset ($cdata, $site_url);
  51. $odata = $db->GetAll("SELECT * FROM `{$tables['link']['name']}` WHERE `OWNER_EMAIL` LIKE ".$db->qstr($rdata['OWNER_EMAIL'])." LIMIT 0 , 30");
  52.  
  53. usort ($odata, "cmp");
  54. $data['RELATED'] = "";
  55. foreach ($odata as $value)
  56. if ($value['ID'] !== $id)
  57. {
  58. if (preg_match ("/\/$/", SITE_URL))
  59. $link = SITE_URL."details.php?id=".$value['ID'];
  60. else
  61. $link = SITE_URL."/details.php?id=" . $value['ID'];
  62.  
  63. $data['RELATED'] .= "<li><a class=\"special\" href=\"{$link}\">{$value['TITLE']}</a></li>\n";
  64. }
  65.  
  66. if($data['RELATED'])
  67. $data['RELATED'] = "<ul>\n{$data['RELATED']}</ul>\n";
  68.  
  69. unset ($odata);
  70. }
  71. }
  72. unset ($rdata);
  73. }
  74. else
  75. $tpl->assign('error', "No ID parameter");
  76.  
  77. $path = array ();
  78. $path[] = array ('ID' => '0', 'TITLE' => _L(SITE_NAME) , 'TITLE_URL' => DOC_ROOT, 'DESCRIPTION' => SITE_DESC);
  79. $path[] = array ('ID' => '0', 'TITLE' => _L('Listing Details'), 'TITLE_URL' => '' , 'DESCRIPTION' => _L('Listing Details'));
  80. $tpl->assign('path', $path);
  81. $tpl->assign($data);
  82.  
  83. $tpl->assign('MetaKeywords' , (!empty ($data['META_KEYWORDS']) ? trim ($data['META_KEYWORDS']) : trim ($MetaKeywords)));
  84. $tpl->assign('MetaDescription', (!empty ($data['META_DESCRIPTION']) ? trim ($data['META_DESCRIPTION']) : trim ($MetaDescription)));
  85.  
  86. //Clean whitespace
  87. $tpl->load_filter('output', 'trimwhitespace');
  88.  
  89. //Compress output for faster loading
  90. if (COMPRESS_OUTPUT == 1)
  91. $tpl->load_filter('output', 'CompressOutput');
  92.  
  93. //Make output
  94. echo $tpl->fetch('detail.tpl', $id);
  95.  
  96. unset ($data);
  97.  
  98. function cmp($a, $b) {
  99. return strcmp ($a["TITLE"], $b["TITLE"]);
  100. }
  101. ?>
also the .htaccess file but I'm not sure if this is needed

PHP Syntax (Toggle Plain Text)
  1. # Protect files
  2. <Files ~ "^(.*)\.(inc|inc\.php|tpl|sql)$">
  3. Order deny,allow
  4. Deny from all
  5. </Files>
  6.  
  7. # Protect directories
  8. <Files ~ "^(backup|files|images|include|lang|libs(/.+)?|temp(/.+)?|templates(/.+)?|javascripts(/.+)?)$">
  9. Order deny,allow
  10. Deny from all
  11. </Files>
  12.  
  13. # Disable directory browsing
  14. Options -Indexes
  15.  
  16. # Follow symbolic links in this directory
  17. Options +FollowSymLinks
  18.  
  19. # Override PHP settings that cannot be changed at runtime
  20. # (If your server supports PHP settings via htaccess you can comment following two lines off)
  21. # php_value register_globals 0
  22. # php_value session.auto_start 0
  23.  
  24. # Customized error messages
  25. # ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
  26. ErrorDocument 404 index.php?httpstatus=404
  27.  
  28. # Set the default handler
  29. DirectoryIndex index.php
  30.  
  31. # URL rewrite rules
  32. <IfModule mod_rewrite.c>
  33. RewriteEngine On
  34.  
  35. ## Details Link Page Rewrite##
  36. RewriteCond %{REQUEST_FILENAME} !-f
  37. RewriteCond %{REQUEST_FILENAME} !-d
  38. RewriteCond %{REQUEST_FILENAME} !-l
  39. RewriteRule (.*)fishing/link-(.*).html$ detail.php [QSA,NC]
  40.  
  41. ## Pagination Rewrite
  42. RewriteCond %{REQUEST_FILENAME} !-f
  43. RewriteCond %{REQUEST_FILENAME} !-d
  44. RewriteCond %{REQUEST_FILENAME} !-l
  45. RewriteRule (.*)page-(\d+)\.html$ $1/?p=$2 [PT,NC]
  46.  
  47. ## Category redirect
  48. RewriteCond %{REQUEST_FILENAME} !-f
  49. RewriteCond %{REQUEST_FILENAME} !-d
  50. RewriteCond %{REQUEST_FILENAME} !-l
  51. RewriteRule ^(.*)$ index.php [QSA,L]
  52.  
  53. </IfModule>
Understand that I am no php expert or anything so thats why I am asking for help. I already posted my question on the forum where I downloaded the script for the directory but I'm getting no responses.

I would appreciate it very much if you could look into this.
please mail me @ dedoo (at) zonnet. nl if you need anything else

Kind regards,
Danny
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dedoo is offline Offline
3 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: download page
Next Thread in PHP Forum Timeline: Accessing PostgreSQL Database from PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC