Click to See Complete Forum and Search --> : Redirect hiding URL


Xeel
April 29th, 2009, 12:20 PM
Hi :wave:
I'm pretty out of ideas in this matter. What I want is to somehow redirect from a controller php class to a php page without altering the url. I'm not a pro in php and maybe missing something. In Java it's done pretty easily using RequestDispatcher, but I know that in php the API is rather limited for this kind of functionality.

My controller model:
- each page contains an eXec parameter that carries a key for path forward so I know what class to execute and where to go go next;
- the controller contains an array with keys and class constructors, session validation, etc. and header() in the end;
- each class extends an interface to inherit the same function which is overloaded in each class where some data processing is made before loading next page;

Just to make myself clear, here are the files examples:

main controller:<?php
//MAIN CONTROLLER >>
require_once("classes/AppInterface.php");
require_once("classes/app_Null.php");
require_once("classes/app_Exit.php");
require_once("classes/app_Login.php");
//...

session_start();
$eXec = isset($_REQUEST["eXec"])?$_REQUEST["eXec"]:"app_logout";
if(isset($_SESSION["sid"]) && $_SESSION["sid"]==1){
$eXec = "app_logout";
}

$nextA = array(
"web_indexp" => new AppNull("login.php"),
"app_logout" => new AppExit("login.php"),
"app_ulogin" => new AppLogin("usher_search.php")
//...
);

$appc = isset($nextA[$eXec])?$nextA[$eXec]:$nextA["app_logout"];
$_SESSION["cPage"] = $appc->execF($_REQUEST);

header("Location: pagex.php");
?>

interface:<?php
interface AppInterface{
public function execF($req);
}
?>

a processing command class example:<?php
class AppNull implements AppInterface{
private $nextPage;

public function AppNull($eXec){
$this->nextPage = $eXec;
}

public function execF($req){
return $this->nextPage;
}
}
?>

pagex.php standart container:<?php
session_start();
include("includes/header.php");
include("includes/title.php");
include("pages/".$_SESSION["cPage"]);
include("includes/footer.php");
?>

What I hate is "mySite/pagex.php" part, I just want ti see "mySite"

I do not want to radically change the flow model so I have to find some solution that just slightly alters it.

Any ideas?

PeejAvery
April 29th, 2009, 12:28 PM
Many times you will see something like post.php?id=423. However, you could do the same using a cookie or session variable to tell a page what to display. Either way, there would have to be some sort of URL change to update the session variable/cookie. There is no way around this on the server-side.

However, if you wanted a simple client-side solution, you could just use a frame the size of the whole page. An example of this would be http://biblescopeapp.com.

Xeel
April 29th, 2009, 12:34 PM
However, if you wanted a simple client-side solution, you could just use a frame the size of the whole page.I'd hated coming to frame frankenstein option. Many php applications do it without frames: almost any framework, most of content managers. I was wondering how though...

Many times you will see something like post.php?id=423.post.php?id=XXX is done mostly to bring joy to web standards and to be able to refer to certain thread/post using direct URL.

However, you could do the same using a cookie or session variable to tell a page what to display.I'm already using session var to change displayed content. In my controller I always call pagex.php, which has include("pages/".$_SESSION["cPage"]); line, where $_SESSION["cPage"] contains a contents page file name.