Overclockers Australia Forums
OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > General Software

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 3rd April 2002, 8:51 PM   #1
dicey Thread Starter
Member
 
Join Date: Jun 2001
Location: Redlands Shire, Brisbane, QLD
Posts: 812
Default Need help with PHP coding.

Hola!

I need help with some PHP coding. I need to see if this is correct. Because it doesn't seem to be correct to me.

I have this in a sep script. Known as bs.php

PHP Code:
<?php
if ($page=='about') include('about.php');
if (
$page=='photoalbum') include('album.php');
if (
$page=='links') include('links.php');
if (
$page=='about-brandon') include('brandon.php');
if (
file_exists($show)){
@include(
"$show");
}else{
@include(
"error404.php");
}
?>
http://www.xis.com.au/~dicey/ <=- this is the site.

What's the problem is. That I'm trying to set a 404 error page. Like this page:

http://www.xis.com.au/~dicey/bs.php?page=drinking

But... When Someone clicks on a link that works. For Example:

http://www.xis.com.au/~dicey/bs.php?page=about

Somehow something is inlcuding the error404.php into any page that works!

It's pissing me off! Please tell me what to do!

Thank you.
__________________
Generalization is all evil.

Total Overdose!!!
Drink or Die!!!

XX- Who has done deals over the OCAU Forum trading area please contact me to put your name on the sig.
dicey is offline   Reply With Quote

Join OCAU to remove this ad!
Old 3rd April 2002, 11:02 PM   #2
mpot
<blank>
 
mpot's Avatar
 
Join Date: Jun 2001
Location: Perth, WA
Posts: 5,345
Default

I know SFA about PHP, but do have experience with a number of other server-side scripting languages....so I'll have a go...

I don't believe you can do conditional includes.

Instead, always @include error404.php on every page.
In error404.php, have a function which will generate the HTML for the 404 error, and call this function when you want to display the 404 error.

Cheers,
Martin.
__________________
[ photography blog | redbubble | flickr ]
mpot is offline   Reply With Quote
Old 3rd April 2002, 11:55 PM   #3
deanx0r
Member
 
deanx0r's Avatar
 
Join Date: Jun 2001
Location: Gold Coast, QLD
Posts: 828
Default

You reckon this would work?

Code:
<?php

if*($page=='about')*include('about.php');

if*($page=='photoalbum')*include('album.php');

if*($page=='links')*include('links.php');

if*($page=='about-brandon')*include('brandon.php');

else {

if*(file_exists($show)){

@include("$show");

}else{

@include("error404.php");

}
}

?>
deanx0r is offline   Reply With Quote
Old 4th April 2002, 2:43 AM   #4
Darkness'
Never a frown..
 
Darkness''s Avatar
 
Join Date: Jun 2001
Location: Sydney
Posts: 4,401
Default

at the very bottom of your about page put a HALT command in there, so it halts all other PHP related commands after it.

Other than that, im not sure. kinda half asleep atm :P
Darkness' is offline   Reply With Quote
Old 4th April 2002, 12:18 PM   #5
Bangers
Member
 
Bangers's Avatar
 
Join Date: Dec 2001
Location: Silicon Valley
Posts: 7,281
Default

PHP Code:
<?php
if ($page=='about'
    include(
'about.php');
else if (
$page=='photoalbum'
    include(
'album.php');
else if (
$page=='links'
    include(
'links.php');
else if (
$page=='about-brandon'
    include(
'brandon.php');
endif;
if (
file_exists($show))
    include(
'$show');
else
    include(
'error404.php');
endif;
?>
an exit command goes after error404 but i forgot what it is
exit;
or like exit(1);

or something

I presume $show is already set to something?
__________________
There's a story about a golfer who sinks a 30-meter putt and someone says: 'Gee, that was lucky' and the golfer says, 'Yes, amazing how lucky you get when you practice 8 hours a day for 20 years'.
Bangers is offline   Reply With Quote
Old 4th April 2002, 12:35 PM   #6
snoopie
Member
 
snoopie's Avatar
 
Join Date: Aug 2001
Location: Sydney
Posts: 1,152
Default

I don't know PHP either but the conditional logic in Bangers post and the original is not the same. That is if the if, else if and else statements have the same meaning as they do in Java, i'd be surprise if they didn't

Here is my guess
PHP Code:
<?php
if ($page=='about'
    include(
'about.php');
endif
if (
$page=='photoalbum'
    include(
'album.php');
endif
if (
$page=='links'
    include(
'links.php');
endif
if (
$page=='about-brandon'
    include(
'brandon.php');
endif;
if (
file_exists($show))
    include(
'$show');
else
    include(
'error404.php');
endif;
?>
__________________
Don't use a big word where a diminutive one will suffice.

Traders List....
(circa September 2003)
snoopie is offline   Reply With Quote
Old 4th April 2002, 1:29 PM   #7
deanx0r
Member
 
deanx0r's Avatar
 
Join Date: Jun 2001
Location: Gold Coast, QLD
Posts: 828
Default

Quote:
Originally posted by Bangers

an exit command goes after error404 but i forgot what it is
exit;
or like exit(1);

or something

I presume $show is already set to something?
I find that just "exit;" works fine, I'm presuming that $show will just be used like "bs.php?show=somepage.php"...
deanx0r is offline   Reply With Quote
Old 4th April 2002, 1:30 PM   #8
MWP
Member
 
MWP's Avatar
 
Join Date: Jun 2001
Location: Adelaide
Posts: 4,636
Default Re: Need help with PHP coding.

Quote:
Originally posted by dicey
Hola!

....

Somehow something is inlcuding the error404.php into any page that works!
I think its beacuse your doing:
if*(file_exists($show))

It wont find the file because its not named right... should be:
if*(file_exists("$show.php"))

?

But the if.. else or using a big switch/case statement would be the best way.
__________________
MWP
PC Database AdminCrystalfontz CrystalControl2 Author - Offical Forums
Motoring Worklog - Toyota V8 RA28 Celica
SA Classic Celica Club Member - Website
MWP is offline   Reply With Quote
Old 4th April 2002, 5:58 PM   #9
Bangers
Member
 
Bangers's Avatar
 
Join Date: Dec 2001
Location: Silicon Valley
Posts: 7,281
Default

Quote:
Originally posted by snoopie
I don't know PHP either but the conditional logic in Bangers post and the original is not the same. That is if the if, else if and else statements have the same meaning as they do in Java, i'd be surprise if they didn't

Here is my guess
PHP Code:
<?php
if ($page=='about'
    include(
'about.php');
endif
if (
$page=='photoalbum'
    include(
'album.php');
endif
if (
$page=='links'
    include(
'links.php');
endif
if (
$page=='about-brandon'
    include(
'brandon.php');
endif;
if (
file_exists($show))
    include(
'$show');
else
    include(
'error404.php');
endif;
?>
naa thats not right because you cant end a if statement then continue it on.

I just released, hes got $page and $show to be 2 different variables when they basically do the same thing.
__________________
There's a story about a golfer who sinks a 30-meter putt and someone says: 'Gee, that was lucky' and the golfer says, 'Yes, amazing how lucky you get when you practice 8 hours a day for 20 years'.
Bangers is offline   Reply With Quote
Old 4th April 2002, 6:24 PM   #10
deanx0r
Member
 
deanx0r's Avatar
 
Join Date: Jun 2001
Location: Gold Coast, QLD
Posts: 828
Default

Actually, this would do the job.
PHP Code:
<?php
$page 
$page '.php';
if (
file_exists($page)) {
  include(
$page);
}
else {
  include(
'error404.php');
}
?>


This does work, I just tried it out. So if he wants to include the about.php file, then the URL is just bs.php?page=about
deanx0r is offline   Reply With Quote
Old 4th April 2002, 6:47 PM   #11
dicey Thread Starter
Member
 
Join Date: Jun 2001
Location: Redlands Shire, Brisbane, QLD
Posts: 812
Default

What I am trying to say is that I want the working pages NOT to inlcude the error404.php into any of the pages.

I want something like if a page exists. Do NOT include the error404.php

If a page that does NOT exist. I want the error404.php to come up in action to let the surfers know that there is a 404.

Please let me know.

Thank you
__________________
Generalization is all evil.

Total Overdose!!!
Drink or Die!!!

XX- Who has done deals over the OCAU Forum trading area please contact me to put your name on the sig.
dicey is offline   Reply With Quote
Old 4th April 2002, 6:58 PM   #12
deanx0r
Member
 
deanx0r's Avatar
 
Join Date: Jun 2001
Location: Gold Coast, QLD
Posts: 828
Default

Yeah dicey that's what the code I used above does, ie.

This link is to an about page I quickly made that does exist:
http://members.lycos.co.uk/deanx0r/test.php?page=about
The about information shown is stored in 'about.php'....

Whereas if you were to go to something that doesn't exist like:
http://members.lycos.co.uk/deanx0r/t...ge=dflkgdfglkg
you'll be presented with my lame 404 page....
deanx0r is offline   Reply With Quote
Old 4th April 2002, 7:03 PM   #13
Chazza
Member
 
Chazza's Avatar
 
Join Date: Jan 2002
Location: Sydney
Posts: 1,112
Default

Took me all of about 30 secs to spot the problem. You havent defined $show. If you still havent figured it out, let me know.
__________________
Chazza
Chazza is offline   Reply With Quote
Old 4th April 2002, 7:06 PM   #14
dicey Thread Starter
Member
 
Join Date: Jun 2001
Location: Redlands Shire, Brisbane, QLD
Posts: 812
Default

Lame question....

Where do I put that in? Do I need to modify it so I can add more links to it?
__________________
Generalization is all evil.

Total Overdose!!!
Drink or Die!!!

XX- Who has done deals over the OCAU Forum trading area please contact me to put your name on the sig.
dicey is offline   Reply With Quote
Old 4th April 2002, 7:11 PM   #15
Bangers
Member
 
Bangers's Avatar
 
Join Date: Dec 2001
Location: Silicon Valley
Posts: 7,281
Default

Quote:
Originally posted by Chazza
Took me all of about 30 secs to spot the problem. You havent defined $show. If you still havent figured it out, let me know.
i saw that too, but i figured he had initialized it earlier.
__________________
There's a story about a golfer who sinks a 30-meter putt and someone says: 'Gee, that was lucky' and the golfer says, 'Yes, amazing how lucky you get when you practice 8 hours a day for 20 years'.
Bangers is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 10:56 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!