Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Prosty system modułów
ghastblood
post
Post #1





Grupa: Zarejestrowani
Postów: 360
Pomógł: 12
Dołączył: 17.09.2009
Skąd: Warszawa

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


Witam,
poszukuje prostego systemu modułów lub podpowiedzi jak taki system powinien działać. Interesował bym mnie kod Proceduralny ponieważ jeszcze się nie przyzwyczaiłem do programowania obiektowego. Zrobiłem sobie coś takiego.
  1.  
  2. if(isset($_SESSION['zalogowany'])) {
  3. }else{
  4. header('location: index.php?id=2');
  5. }
  6. $sql_wynik = dbquery("SELECT * FROM plugins WHERE plugin_number='".$_GET['id']."' && plugin_side = '2'");
  7.  
  8. $r = dbarray($sql_wynik);
  9. if($r == NULL){
  10. echo 'plugin nie istnieje';
  11. } else{
  12. include $r['plugin_path']."/".$r['plugin_start'];
  13. }


Problem w tym że przeglądarka zwraca mi błąd że Ta strona internetowa zawiera pętlę przekierowań. Gdy robię przekierowanie na inny plik w header to jest dobrze gdy chce przekierować na index.php?id=2 czy każde inne id to wywala mi błąd.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


to był tylko przykład.. i lepszy niż te twoje switche - tak to już chyba nikt nie pisze ;p

a to czy ma działać czy nie robisz w równie prosty sposób
  1. $modules = array(
  2. 'index' => array('file' => 'module/index.php', 'status' => 1),
  3. 'login' => array('file'=>'module/login.php', 'status' => 0),
  4. 'reg' => array('file'=>'module/auth/register.php', 'status' => 1)
  5. );
  6.  
  7. $id = strtolower($_GET['id']);
  8.  
  9. if(array_key_exists($id, $modules) && $modules[$id]['status'] == 1) {
  10.  
  11. include $modules[$id];
  12. }


Ten post edytował CuteOne 18.07.2012, 00:51:28
Go to the top of the page
+Quote Post
ghastblood
post
Post #3





Grupa: Zarejestrowani
Postów: 360
Pomógł: 12
Dołączył: 17.09.2009
Skąd: Warszawa

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


Cytat(CuteOne @ 18.07.2012, 01:48:28 ) *
to był tylko przykład.. i lepszy niż te twoje switche - tak to już chyba nikt nie pisze ;p

a to czy ma działać czy nie robisz w równie prosty sposób
  1. $modules = array(
  2. 'index' => array('file' => 'module/index.php', 'status' => 1),
  3. 'login' => array('file'=>'module/login.php', 'status' => 0),
  4. 'reg' => array('file'=>'module/auth/register.php', 'status' => 1)
  5. );
  6.  
  7. $id = strtolower($_GET['id']);
  8.  
  9. if(array_key_exists($id, $modules) && $modules[$id]['status'] == 1) {
  10.  
  11. include $modules[$id];
  12. }


wywala i taki błąd

  1. Notice: Array to string conversion in C:\xampp\htdocs\mtgcon_ver.0.1\index.php on line 27
  2.  
  3. Warning: include(Array) [function.include]: failed to open stream: No such file or directory in C:\xampp\htdocs\mtgcon_ver.0.1\index.php on line 27
  4.  
  5. Warning: include() [function.include]: Failed opening 'Array' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mtgcon_ver.0.1\index.php on line 27


dobra mam powinno być tak
  1. if(array_key_exists($id, $modules) && $modules[$id]['status'] == 1) {
  2.  
  3. include $modules[$id]['file'];
  4. }


Ten post edytował ghastblood 18.07.2012, 11:38:15
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 26.09.2025 - 13:28