Require and URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kazbaeden
Forum Newbie
Posts: 7
Joined: Fri Dec 05, 2003 1:02 pm

Require and URL

Post 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?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Re: Require and URL

Post 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;
?>
Kazbaeden
Forum Newbie
Posts: 7
Joined: Fri Dec 05, 2003 1:02 pm

Post 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!
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post 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.
Post Reply