PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > on using 'request_uri' to make a front-end site
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
on using 'request_uri' to make a front-end site

Réponse
 
LinkBack Outils de la discussion
Vieux 17/03/2008, 12h45   #1
Donn Ingle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut on using 'request_uri' to make a front-end site

Hi,
I have been trying to get a little templating thing going and I want
everything to pass through a single index.php file which then decides what
page is wanted and includes them.

The scheme is to go to a url like [http://localhost/~donn/blah/] which
serves index.php in that dir. That includes 'home.php'

home.php has a link to 'use1.php'

The problem I am having is that as I click back and forth between home and
use1 the url starts growing...

I get things like [http://localhost/~donn/blah/index.php/index.php/use1] and
it just keeps getting longer.

I include my code below, very much shortened. I am sure I am missing some
obvious way to control links in this weird situation where every page is
*really* index.php but I still need to link from page to page.

[code]
[index.php]
<?php
$expl = explode("/",$_SERVER["REQUEST_URI"]);
$resource = $expl[count($expl)-1];
if ($resource=="") $resource="home";

if (file_exists($resource.".php") ) {
include $resource.".php";
} else {
echo "No such file.";
}
?>

[home.php]
<h1>home</h1>
<a href="index.php/use1">link to use1</a>

[use1.php]
<h1>use1</h1>
<a href="index.php/home">Back</a>

The overall idea is to have clean urls without a bunch of htaccess stuff
(which mystifies me). I want to be able to bookmark
[http://localhost/~donn/blah/index.php/somepage] and have stuff like
[http://localhost/~donn/blah/index.php/gallery:showpic1]

Thanks for reading.
\d



  Réponse avec citation
Vieux 17/03/2008, 17h03   #2
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on using 'request_uri' to make a front-end site

UsDonn Ingle wrote:
> Hi,
> I have been trying to get a little templating thing going and I want
> everything to pass through a single index.php file which then decides what
> page is wanted and includes them.
>
> The scheme is to go to a url like [http://localhost/~donn/blah/] which
> serves index.php in that dir. That includes 'home.php'
>
> home.php has a link to 'use1.php'
>
> The problem I am having is that as I click back and forth between home and
> use1 the url starts growing...
>
> I get things like [http://localhost/~donn/blah/index.php/index.php/use1] and
> it just keeps getting longer.
>
> I include my code below, very much shortened. I am sure I am missing some
> obvious way to control links in this weird situation where every page is
> *really* index.php but I still need to link from page to page.
>
> [code]
> [index.php]
> <?php
> $expl = explode("/",$_SERVER["REQUEST_URI"]);
> $resource = $expl[count($expl)-1];
> if ($resource=="") $resource="home";
>
> if (file_exists($resource.".php") ) {
> include $resource.".php";
> } else {
> echo "No such file.";
> }
> ?>
>
> [home.php]
> <h1>home</h1>
> <a href="index.php/use1">link to use1</a>
>
> [use1.php]
> <h1>use1</h1>
> <a href="index.php/home">Back</a>
>
> The overall idea is to have clean urls without a bunch of htaccess stuff
> (which mystifies me). I want to be able to bookmark
> [http://localhost/~donn/blah/index.php/somepage] and have stuff like
> [http://localhost/~donn/blah/index.php/gallery:showpic1]
>
> Thanks for reading.
> \d
>
>
>

Use /index.php instead of index.php maybe...
  Réponse avec citation
Vieux 17/03/2008, 20h27   #3
Donn Ingle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on using 'request_uri' to make a front-end site

Shawn McKenzie wrote:
> Use /index.php instead of index.php maybe...

I assume you meant in the <a> tag. I tried that and the URL (when you
mouse-over the link) becomes [http://localhost/index.php] which is not
anywhere near where the files live.

I must say I am rather confused by this situation, but I can fix it by
always using absolute urls - which is a bit of a pain.

\d

  Réponse avec citation
Vieux 18/03/2008, 00h07   #4
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on using 'request_uri' to make a front-end site

Donn Ingle wrote:
> Shawn McKenzie wrote:
>> Use /index.php instead of index.php maybe...

> I assume you meant in the <a> tag. I tried that and the URL (when you
> mouse-over the link) becomes [http://localhost/index.php] which is not
> anywhere near where the files live.
>
> I must say I am rather confused by this situation, but I can fix it by
> always using absolute urls - which is a bit of a pain.
>
> \d
>

Does seem strange. Try:

<head>
<base href="http://localhost/~donn/blah/index.php" />
</head>

Then just use /home, /use1 etc... Might work.

-Shawn
  Réponse avec citation
Vieux 18/03/2008, 09h50   #5
Donn Ingle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on using 'request_uri' to make a front-end site

Shawn McKenzie wrote:
> Does seem strange. ÂTry:
> <head>
> <base href="http://localhost/~donn/blah/index.php" />
> </head>
> Then just use /home, /use1 etc... ÂMight work.

Right, I'll give it a go. It's not much different from wiring-in a php var
naming the base with {$base}/use1 being the form.

The thing that would here is if I could get a reliable way to extract
the working 'path' (from an http:// pov) from the $_SERVER array somehow.
Each of them gives a result tantalizingly close to the base, but they get
it wrong in various ways.

Well, thanks for your .

\d

  Réponse avec citation
Vieux 18/03/2008, 12h02   #6
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: on using 'request_uri' to make a front-end site

> The thing that would here is if I could get a reliable way to extract
> the working 'path' (from an http:// pov) from the $_SERVER array somehow.
> Each of them gives a result tantalizingly close to the base, but they get
> it wrong in various ways.


You can use $_SERVER['PHP_SELF'] which will give you the path to the
script or $_SERVER['REQUEST_URI'] (you will probably have to remove the
query string with this), along with either dirname().

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
  Réponse avec citation
Vieux 18/03/2008, 12h27   #7
Donn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: on using 'request_uri' to make a front-end site

On Tuesday, 18 March 2008 12:02:14 Richard Heyes wrote:
> You can use $_SERVER['PHP_SELF'] which will give you the path to the
> script or $_SERVER['REQUEST_URI'] (you will probably have to remove the
> query string with this), along with either dirname().


The problem is that the URL does not stay constant, it keeps growing. For
example after clicking between home and use1 a few times I see these values,
note how index.php repeats:

'REQUEST_URI':/~donn/template-dev/routertest/index.php/index.php/home
dirname('REQUEST_URI'):/~donn/template-dev/routertest/index.php/index.php

I suppose some kind of htaccess voodoo could here, but I am in no shape
to grok those murky waters.

A link <a href="index.php/use1"> causes 'index.php/use1' to be appended to the
full url [http://localhost/~donn/template-dev/routertest/] and at first, it's
fine but after a few clicks, it keeps appending. Amazingly things still work,
but the URL is out of control!

All I can think to use to enforce correct link behaviour is to employ absolute
urls.

Thanks for the feedback.
\d
  Réponse avec citation
Vieux 18/03/2008, 12h37   #8
Richard Heyes
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Re: on using 'request_uri' to make a front-end site

> A link <a href="index.php/use1"> causes 'index.php/use1' to be appended to the
> full url [http://localhost/~donn/template-dev/routertest/] and at first, it's
> fine but after a few clicks, it keeps appending. Amazingly things still work,
> but the URL is out of control!


Links that don't start with a / are taken to be relative to the current
documents path. You (probably) want this:

<a href="/~donn/blah/index.php/use1">

The forward slash at the start causes your browser to ignore whatever
your current path is, albeit remain on the current domain.

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
  Réponse avec citation
Vieux 18/03/2008, 15h22   #9
Donn Ingle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Re: on using 'request_uri' to make a front-end site

Richard Heyes wrote:

> The forward slash at the start causes your browser to ignore whatever
> your current path is, albeit remain on the current domain.

Okay, I think I am getting confused by this ~donn/ virtual path thing. I
will try your suggestion it looks good.

Thanks.
\d

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 04h06.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14685 seconds with 17 queries