Page 1 of 1

Require and URL

Posted: Mon Jan 12, 2004 7:58 pm
by Kazbaeden
I'm pretty new to PHP so this stuff is probably pretty basic. What I'm trying to do is have a shell for the layout, and use require() to add content. When a user clicks on a link, the content should change.

So I tried this:

Code: Select all

<?php
if ($_SERVER&#1111;'REQUEST_URI'] = "/index.php")
&#123;
require("no.html");
&#125;
else
require( $_GET&#1111;'action'] . ".html");
?>
What my thought was, was taht the script would take the requested URL, and if it was index.php, it would include the default page. When a link was clicked, it would add ?action=URL to the URL of the page, and depending what was added, that file would be included. Apparantly this isn't working, because when the page reloads and ?action is on the end, the URI still equals "/index.php"

Any help on this or a better method?

Re: Require and URL

Posted: Mon Jan 12, 2004 8:16 pm
by Straterra
Kazbaeden wrote:I'm pretty new to PHP so this stuff is probably pretty basic. What I'm trying to do is have a shell for the layout, and use require() to add content. When a user clicks on a link, the content should change.

So I tried this:

Code: Select all

<?php
if ($_SERVER&#1111;'REQUEST_URI'] = "/index.php")
&#123;
require("no.html");
&#125;
else
require( $_GET&#1111;'action'] . ".html");
?>
What my thought was, was taht the script would take the requested URL, and if it was index.php, it would include the default page. When a link was clicked, it would add ?action=URL to the URL of the page, and depending what was added, that file would be included. Apparantly this isn't working, because when the page reloads and ?action is on the end, the URI still equals "/index.php"

Any help on this or a better method?
It will always equal. You want to use double equal signs... Also, your else should have a bracket after it..And you should close the if statements with another bracket..Here is the revised code...

Code: Select all

<?php
if ($_SERVER&#1111;'REQUEST_URI'] == "/index.php") &#123;
require("no.html");
&#125; else &#123;
require( $_GET&#1111;'action'] . ".html");
&#125;
?>

Posted: Mon Jan 12, 2004 9:29 pm
by Kazbaeden
I guess those are the mistake a noob makes then. So = is to set equal to and == is to compare to. Gotcha. Thanks a lot!

Posted: Mon Jan 12, 2004 9:32 pm
by Pyrite
Or you could use a switch statement instead.

Like /index.php?page=news

switch ($_GET['page']) {
case "news":
require news
case "links"

etc like that.