|
-
April 29th, 2009, 12:20 PM
#1
Redirect hiding URL
Hi 
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 Code:
<?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 Code:
<?php interface AppInterface{ public function execF($req); } ?>
a processing command class example:
PHP Code:
<?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 Code:
<?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?
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
April 29th, 2009, 12:28 PM
#2
Re: Redirect hiding URL
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
April 29th, 2009, 12:34 PM
#3
Re: Redirect hiding URL
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.
Last edited by Xeel; April 29th, 2009 at 12:56 PM.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|