Ankündigung

Einklappen
Keine Ankündigung bisher.

Kann kein header(); nutzen...

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Kann kein header(); nutzen...

    Guten Tag liebe Community!
    Derzeit arbeite ich an meiner Content Management System und muss eine Weiterleitung machen.

    Als ich nun header(); nutze, werde ich nicht weitergeleitet....
    Liegt es ev. an meinem MVC-Anwendung?

    Controller.php:
    PHP-Code:
    <?php
    namespace Daily\System;
    use \
    Daily\System\View as View;

    class 
    Controller {
      public function 
    getModel($model) {
        if(
    file_exists($path 'application/models/'.$model.'Model.php')) {
          
    $models sprintf('\\Daily\\Application\\Models\\%sModel'$model);
          if(!
    class_exists($models)) {
            echo 
    sprintf('Class %s not found!'$model.'Model');
          }
          return new 
    $models();
        }
      }

      public function 
    getView() {
        return new 
    View;
      }
    }
    Routing.php
    PHP-Code:
    <?php
    namespace Daily\System;

    class 
    Routing {
      public function 
    __construct() {
        
    self::process();
      }

      public static function 
    process() {
        
    $get = (empty($_GET['site'])) ? '' $_GET['site'];
        
    $get trim($get'/');
        
    $get explode('/'$get);

        if(empty(
    $get[0])) {
          if(
    file_exists('application/controllers/IndexController.php')) {
            
    $Index = new \Daily\Application\Controllers\IndexController;
            
    $Index->Main();
            return 
    FALSE;
          }
        }

        if(isset(
    $get[0])) {
          if(
    file_exists('application/controllers/'.ucfirst($get[0]).'Controller.php')) {
            
    $controller sprintf("\\Daily\\Application\\Controllers\\%sController"ucfirst($get[0]));

            if(!
    class_exists($controller)) {
              echo 
    sprintf("Class %s not Found"$get[0].'Controller');
            }

            
    $controller = new $controller;

            if(!
    method_exists($controller'Main')) {
              echo 
    'Methode "Main" wurde nicht gefunden!';
            }

            
    $controller->Main();

          } else {
            echo 
    'File not found!';
          }
        }

        if(isset(
    $get[1])) {
          if(!
    method_exists($controller$get[1])) {
            echo 
    sprintf('<br />Method %s not found!'$get[1]);
          }
          
    $controller->{$get[1]}($get[1]);
        }

        if(isset(
    $get[2])) {
          if(!
    method_exists($controller$get[2])) {
            echo 
    sprintf('<br />Method %s not found!'$get[2]);
          }
          
    $controller->{$get[2]}($get[2]);
        }

        if(isset(
    $get[3])) {
          if(!
    method_exists($controller$get[3])) {
            echo 
    sprintf('<br />Method %s not found!'$get[3]);
          }
          
    $controller->{$get[3]}($get[3]);
        }

        if(isset(
    $get[4])) {
          if(!
    method_exists($controller$get[4])) {
            echo 
    sprintf('<br />Method %s not found!'$get[4]);
          }
          
    $controller->{$get[4]}($get[4]);
        }
      }

    }
    Und nochmal mein IndexControler.php
    PHP-Code:
    <?php
    namespace Daily\Application\Controllers;
    use \
    Daily\System\Controller as Controller;

    class 
    IndexController extends Controller {
      public function 
    Main() {
        
    $this->getView()->display('Index/Index');
      }

      public function 
    Login() {
        require_once 
    'application/openID.php';
        
    $openID = new \LightOpenID("localhost");
        
    $api "5044B0379C31408758006FFEF44F0CAD";
          if(!
    $openID->mode) {
            
    $openID->identify "http:://steamcommunity.com/openid";
            
    $this->getView()->redirect($openID->authURL());
          } elseif(
    $openID->mode == "cancel") {
            echo 
    "User has canceled Authentification";
          } else {
            if(!isset(
    $_SESSION['T2SteamAuth'])) {
              
    $_SESSION['T2SteamAuth'] = $openID->validate() ? $openID->identify null;
              
    $_SESSION['T2SteamID64'] = str_replace("http://steamcommunity.com/openid/id"$_SESSION['T2SteamAuth']);

              if(
    $_SESSION['T2SteamAuth'] != null) {
                
    $Steam64 str_replace("http://steamcommunity.com/openid/id"$_SESSION['T2SteamAuth']);
                
    $profile file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayersSummeries/v0002/?key={$api}%steamids={$Steam64}");
                
    $buffer fopen("cache/{$steam64}.json""w+");
                
    fwrite($buffer$profile);
                
    fclose($buffer);
              }

              
    header("Location: /index");
            }
          }
      }
    }
    Hatte auch ein var_dump(); auf header(); gemacht, und bekam nur folgendes als Ergebnis:
    string(26) "Location: http://google.de"

    MfG.

  • #2
    Mach direkt nach dem
    PHP-Code:
    header(...); 
    mal ein
    PHP-Code:
    exit; 
    PHP-Code:
    header("Location: /index");
    exit; 
    Warum das file_exists()?

    Kommentar


    • #3
      Zitat von rkr Beitrag anzeigen
      Warum das file_exists()?
      Na ja, um zu schauen, ob das Model existiert oder der jeweilige Controller.
      Und die Methode mit dem exit; unter dem Header(); funktioniert leider nicht.

      Aber wenn ich /index/login aufrufe, bekomme ich darunter folgende Fehlermeldung:
      Code:
      Fatal error: Uncaught exception 'ErrorException' with message 'No identity supplied.' in /Applications/XAMPP/xamppfiles/htdocs/application/openID.php:405 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/application/openID.php(671): LightOpenID->discover(NULL) #1 /Applications/XAMPP/xamppfiles/htdocs/Application/Controllers/IndexController.php(16): LightOpenID->authUrl() #2 /Applications/XAMPP/xamppfiles/htdocs/System/Routing.php(47): Daily\Application\Controllers\IndexController->Login('login') #3 /Applications/XAMPP/xamppfiles/htdocs/System/Routing.php(6): Daily\System\Routing::process() #4 /Applications/XAMPP/xamppfiles/htdocs/index.php(13): Daily\System\Routing->__construct() #5 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/application/openID.php on line 405
      Liegt anscheinend daran, dass der User nicht eingeloggt ist (openID Steam).
      MfG.

      Kommentar


      • #4
        Zitat von xkl01l Beitrag anzeigen
        Na ja, um zu schauen, ob das Model existiert oder der jeweilige Controller.
        Schau dir mal Slim an. Das ist ein Router, der das was du da machst wesentlich besser macht.

        Kommentar


        • #5
          Zitat von rkr Beitrag anzeigen
          Warum? Was passiert, wenn nicht?
          Wird dann folgendes ausgegeben:
          "File not found"....

          Kommentar


          • #6
            Zitat von xkl01l Beitrag anzeigen
            Wird dann folgendes ausgegeben:
            "File not found"....
            Ich habe meinen Beitrag noch mal editiert, weil ich das dann auch verstanden habe

            Kommentar

            Lädt...
            X