Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [.htaccess + php] Katalogowanie bez i ze slashem na końcu
DonJeday
post 23.11.2008, 08:57:42
Post #1





Grupa: Zarejestrowani
Postów: 113
Pomógł: 0
Dołączył: 24.10.2008
Skąd: Częstochowa

Ostrzeżenie: (0%)
-----


Witam,



Chcę wczytać profile użytkowinków w formie http://adres.pl/profile/xxx



Niby wszystko działa, rzeczywiście wczytuje mi te profile ze slashem i bez na końcu ale jak pobieram dane o danym userze i jest slash na końcu wyskakuje mi że konto nie istnieje, a bez slasha jest ok.

.htaccess:

Kod
RewriteRule ^profile/(.+)/?$ ./profile.php?go=$1


Wyświetlanie profilu:

  1. <?php
  2. try {
  3.  $pdo = new PDO('mysql:host=localhost;dbname=xxx', 'xxx', 'xxx',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  4.  $pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  5.  $query = $pdo -> prepare('SELECT * FROM users WHERE login = :login LIMIT 1');
  6.  $query -> bindValue(':login', $_GET['go'], PDO::PARAM_STR);
  7.  $query -> execute();
  8.  $row = $query -> fetch(PDO::FETCH_ASSOC);
  9.  $query -> closeCursor();
  10.  if($row==true)
  11.  {
  12.      $smarty->assign('user_data', $row);
  13.      $smarty->display('profile.tpl');
  14.  } else {
  15.      $smarty->assign('style','error');
  16.      $smarty->assign('message_title','Profil nie istnieje!');
  17.      $smarty->assign('message_text','Podany profil nie istnieje. Prosimy upewnić się, że dobrze wpisałeś/aś adres profilu.');
  18.      $smarty->assign('message_back','../index.html');
  19.      $smarty->display('message.tpl');
  20.  }
  21. }
  22. catch(PDOException $e) {
  23.  echo 'Połączenie nie mogło zostać utworzone: ' . $e->getMessage();
  24. }
  25. ?>


Jak zrobić by profil wyświetlało i ze slashem i bez na końcu?

Ten post edytował DonJeday 23.11.2008, 08:58:34


--------------------
Go to the top of the page
+Quote Post
Noddi
post 23.11.2008, 10:28:24
Post #2





Grupa: Zarejestrowani
Postów: 45
Pomógł: 7
Dołączył: 25.12.2004
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Kod
RewriteRule ^profile/([a-z0-9]+)/?$ ./profile.php?go=$1


Przy [.+] pobiera Ci / jako dowolny znak przy adresie /profile/test/


--------------------
"Yes, experience matters. No, one year repeated fifteen times does not count."
bartoszlugowski.com
Go to the top of the page
+Quote Post
phpion
post 23.11.2008, 10:30:43
Post #3





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Masz 2 wyjścia:
Kod
RewriteRule ^profile/([A-Za-z0-9_]+)/?$ ./profile.php?go=$1

lub:
  1. <?php
  2. $query -> bindValue(':login', str_replace('/', '', $_GET['go']), PDO::PARAM_STR);
  3. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 15.07.2025 - 09:49