Jump to content


code not working!


9 replies to this topic

#1 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 15 March 2006 - 07:22 PM

	  <?php 

switch($page) {
default: 
include('news.php'); 
break; case "tutorials": 
include('tutorials.php'); 
break; case "resources": 
include('resources.php'); 
break; case "contact": 
include('contact.php');
break; case "apply": 
include('addsite.php'); 
break; case "tuts": 
include('tuts.php'); 
break; case "affview": 
include('affviewall.php'); 
break; case "home": 
include('news.php'); 
break; case "applyaff": 
include('aff/index.php');   
break; case "viewall": 
include('affviewall.php'); 
break; case "brushes":
include ('brushes.php');
break; case "graphics":
include ('graphics.php');
break; case "renders":
include ('renders.php');
 } 

 ?>

Thats my code and as you can see its long
Its been working for a while until acouple of days ago.. and now it doesnt work

i link like so:
?page=PAGE

http://darkpixels.net/?page=contact < WOULD NOT WORK
http://darkpixels.net/contact.php < WORKS

Why?

#2 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 15 March 2006 - 08:26 PM

try this.
<?php
$page = $_GET['page'];
switch($page) {
default:
include('news.php');
break; 

case "tutorials":
include('tutorials.php');
break; 

case "resources":
include('resources.php');
break; 

case "contact":
include('contact.php');
break;

case "apply":
include('addsite.php');
break; 

case "tuts":
include('tuts.php');
break; 

case "affview":
include('affviewall.php');
break; 

case "home":
include('news.php');
break; 

case "applyaff":
include('aff/index.php');  
break; 

case "viewall":
include('affviewall.php');
break; 

case "brushes":
include ('brushes.php');
break; 

case "graphics":
include ('graphics.php');
break; 

case "renders":
include ('renders.php');
break;
}

?>

Edited by coolaid, 15 March 2006 - 08:27 PM.


#3 BigDog

    Young Padawan

  • Members
  • Pip
  • 277 posts
  • Gender:Male
  • Location:Orange County, California
  • Interests:Running, building computers, PC games and BMX and programming.

Posted 15 March 2006 - 08:30 PM

Thank alot coolaid, I was wondering why it worked before and not now, could it be that my Host upgraded to PHP 5 and php 5 has some new features or something?

but thanks!

#4 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 15 March 2006 - 08:32 PM

yea in php5 variable handling is just a tiny bit different. if the variable is a cookie, input data, or strait from the url, it has to have its $_COOKIE['name'], $_POST['name'], or $_GET['name'].

and in this case, the var came strait from the url so it had to be $_GET['name']

plus you forgot to add break; to your very last case.

#5 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 16 March 2006 - 02:36 PM

I've said this on the forum before! There is an easier way to do this!!
if (isset($_GET['page'])){  //If there is a page being loaded
	if (file_exists($_GET['page'].'.php')){ // checks to see if the page exists
	   include($_GET['page'].'.php'); //if it does include it
	}else{
	   echo 'error page not found'; //if it doesn't say this
	}
}else{
	include('news.php'); //if ?page isn't set display the news
}

And for your "applyaff" page, simply make the ?page=aff/index

Edited by Lang, 16 March 2006 - 02:37 PM.


#6 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 16 March 2006 - 04:24 PM

i dont understand why you think thats easier or better.... explain?

#7 Nerdstyle

    Young Padawan

  • Members
  • Pip
  • 29 posts

Posted 16 March 2006 - 04:30 PM

Cause you don't have to name each page in the php... I still don't get what the point of the whole thing is though then?

#8 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 16 March 2006 - 06:14 PM

oh yea, i see it now. but if the casename isn't the name of the file, you'd have to change the casename, or the filename...... its pretty good actually...

#9 tiki

    Young Padawan

  • Members
  • Pip
  • 259 posts
  • Gender:Male
  • Location:California

Posted 17 March 2006 - 01:27 AM

If say page=Contact you just use strtolower($_GET["page"]); then it will echo contact.php... and vice versa.

#10 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 17 March 2006 - 05:48 PM

The whole topic of file inclusion, what's easier to use, and which is more secure has been discussed before. If anybody wants to further read into it, please use the forum search feature.

As for why your script suddenly stopped working, it may or may not be because of upgrading to php 5, because i had the same problem before php 5 was even out.
http://php.net/register_globals <-- Note: This has been discussed here before, but it's here for your reference.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users