Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Przekierowanie z HTTP_HOST i REQUEST_URI NIE DZIALA
Skorpiono
post 28.09.2019, 22:12:54
Post #1





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 31.10.2007

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


Otoz mam taki problem mam 3 pliki, config. php, index.php i requestprocessor.php

config to wiadomo, stale.

mam w nim cos takiego

  1. <?php
  2.  
  3. //$sitetitle = "Rechniewskiego-United";
  4.  
  5. define("SITE_NAME", "Rechniewskiego-United");
  6.  
  7. // Define DB Params
  8. define("DB_HOST", "localhost");
  9. define("DB_USER", "root");
  10. define("DB_PASS", "");
  11. define("DB_NAME", "tajemnica");
  12.  
  13. //Define URL
  14. define("ROOT_LANDING_URL", "serwer1937930.home.pl");
  15. define("ROOT_APP_URL", "app.serwer1937930.home.pl");
  16. define("ROOT_SHORT_URL", "inny_url.pl");
  17.  
  18. foreach (glob ("app/*.php") as $filename) {
  19. include $filename ;
  20. }
  21.  
  22. include_once("RequestProcessor.php");
  23.  
  24. ?>


Jak widac znajduja sie w nim stale ktore odpowiadaja zmiennej superglobalnej HTTP_HOST

Nastepnie jest index.php

  1. <?php
  2. require_once('config.php');
  3.  
  4.  
  5. use Aplikacja as app;
  6.  
  7. $processor = new app\RequestProcessor();
  8.  
  9. switch($_SERVER['HTTP_HOST'])
  10. {
  11. case ROOT_LANDING_URL:
  12. $processor->processLandingRequest($_SERVER['REQUEST_URI']);
  13. break;
  14. case ROOT_APP_URL:
  15. $processor->processAppRequest($_SERVER['REQUEST_URI']);
  16. break;
  17. case ROOT_SHORT_URL:
  18. $processor->processShortRequest($_SERVER['REQUEST_URI']);
  19. break;
  20. default:
  21. header("Location:http://" . ROOT_LANDING_URL);
  22. break;
  23. }
  24. ?>


Jak widac, odbiera on stala app.blablabla i gdy domena zgadza sie z ta zapisana wysyla mnie do procesora

Procesor tworzy instancje klasy Dashboard() i odsyla mnie do metody ProcessRequest, REQUEST_URI jest walniety do konstruktora klasy

  1. <?php
  2.  
  3. namespace Aplikacja;
  4.  
  5. class RequestProcessor
  6. {
  7. public function processShortRequest($request) {
  8. $shortener = new Shortener();
  9. $shortener->RedirectToDestinationUrl(str_replace('/', '', $request));
  10. }
  11.  
  12. public function processAppRequest($request) {
  13. $dashboard = new Dashboard($request);
  14. $dashboard->ProcessRequest();
  15. }
  16.  
  17. public function processLandingRequest($request) {
  18. require("landingpage.view.php");
  19. }
  20. }


dalej

  1. <?php
  2.  
  3. namespace Aplikacja;
  4.  
  5. class Dashboard
  6. {
  7. private $request;
  8. private $post;
  9. private $get;
  10.  
  11. public function __construct($request){
  12. $requestString = explode("?", $request);
  13. $this->request = empty($requestString) ? $request : $requestString[0];
  14. //$this->request = $request;
  15. }
  16.  
  17. public function ProcessRequest()
  18. {
  19. if(!$this->request)
  20. {
  21. return;
  22. //echo "cos sie zjebalo";
  23. }
  24.  
  25. $this -> post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
  26. $this -> get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
  27.  
  28. switch ($this->request)
  29. {
  30. case "/piramida/registerForm/":
  31. echo "test turinga";
  32. //$this->showRegister();
  33. break;
  34. case "/piramida/":
  35. $this->showDashboard($this->request);
  36. break;
  37.  
  38. case "/piramida/loginForm":
  39. $this->showLogin();
  40. break;
  41. //dalsze inputy
  42. default:
  43. $this->showDashboard("as");
  44. break;
  45.  
  46. }
  47. //echo $this->request;
  48. }


Konstruktor pobiera dane i zwraca wartosc bez zmiennych GET do pola $this->request. Nastepnie sprawdzam w switchu wartosc requesta i porownuje ze stringiem. I o ile case "/piramida/" dziala (nazwa podfolderu na hoscie) to reszta w ogole i wywala mi blad 404. w ogole nie wiem, dlaczego. Wie ktos?
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: 29.03.2024 - 05:58