Jump to content

*SOLVED* variable problem


salvador2001

Recommended Posts

hi all,

I am very noob with PHP and i cant get this script working right.
Now i got a variable error on the section "load in directory"

Can anyone please adjust this script for me ?

<?php

// load existing pages

if(isset($_GET['load'])) {
switch($_GET['load']) {
case 'news':
case 'about':
case 'members':
$load = $_GET['load'];
break;
default:
$load = 'welcome';
}
}

// load in root directory

if (is_file($load . ".php")) {
include($load . ".php");
}

// load errorpage

else {
include("error404.php");
}

?>
Link to comment
https://forums.phpfreaks.com/topic/6835-solved-variable-problem/
Share on other sites

The problem is that if $_GET['load'] isn't set, then the variable $load isn't defined. Do this before your switch to make sure that $load is always defined:
[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code] or something similar.

Ken
Link to comment
https://forums.phpfreaks.com/topic/6835-solved-variable-problem/#findComment-24915
Share on other sites

Thanks a lot !, the error message is gone.
But now there is one thing left, it keeps loading the errorpage at start while it should display the welcome page. Its a dynamic page so he doesnt load the content it should.
any idea what is going wrong ?

This is the script so far;

<?php

// only this pages are allowed

if(isset($_GET['load'])) {
switch($_GET['load']) {
case 'news':
case 'about':
case 'members':
$load = $_GET['load'];
break;
default:
$load = 'welcome';
}
}

// load files in rootdirectory

if (!empty($load)) {
if (is_file($load . ".php")) {
include($load . ".php");
}
}

// loading error page

else {
include("error404.php");
}

?>
Link to comment
https://forums.phpfreaks.com/topic/6835-solved-variable-problem/#findComment-25011
Share on other sites

If you had implemented my suggestion instead of the one from [b]Yesideez[/b] you it would be working.

Here is my suggestion again:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Do this before your switch to make sure that $load is always defined:
[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code][/quote]

Ken
Link to comment
https://forums.phpfreaks.com/topic/6835-solved-variable-problem/#findComment-25017
Share on other sites

Thanks, someone got it solved for me and its working. For other people this could be a good example so i post the working script here.

[code]<?php  

// only this pages are allowed

if(isset($_GET['load'])) {  
  switch($_GET['load']) {  
    case 'news':  
    case 'about':  
    case 'members':  
      $load = $_GET['load'];  
      break;  
    default:  
      $load = 'welcome';  
  }
} else {
  $load = 'welcome';    // -- if $_GET['load'] is not defined
}  

// load files in rootdirectory

if (is_file($load . ".php")) {  
include($load . ".php");  
}  

// loading errorpage

else {  
include("error404.php");  
}  

?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/6835-solved-variable-problem/#findComment-25022
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.