Jump to content

[SOLVED] isset help


adam291086

Recommended Posts

Once you do

<?php
$page = $_GET['page'];
?>

Then the variable $page is set. You should be doing something like this:

<?php
$page = (isset($_GET['page']))?$_GET['page']:'index';
?>

 

Make sure you validate the results before going to that page or including it.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/82516-solved-isset-help/#findComment-419459
Share on other sites

Thanks guys it was because of the extra ; by the isset

 

The reason why i am checking if $_GET isset is because it's determining which page content to load from the database. If a user goes to ryedalerumble.co.uk there is nothing no indicate which content to load. Therefore set it $page to 'index'. If a user clicks on a link the url becomes ryedalerumble.co.uk/?page=index and therefore i get the page = part and search the database for it.

 

Is this the best way?

 

Link to comment
https://forums.phpfreaks.com/topic/82516-solved-isset-help/#findComment-419467
Share on other sites

Setting the default page to 'index' in the case of no $_GET page is pretty easy. Mostly re-iterating what others have said.

 

<?php

$page = $HTTP_GET_VARS['page'];

if ( !$page )
{
  // Your index page here

  include( 'index.htm' );
}
else
{
  // Other page

  include( $page . '.htm' );
}

?>

 

You should somehow predefine all your pages to the $_GET page in the URL can be 'validated'. Otherwise the script will try to include ANY page the a mischievous user enters.

 

<?php

$my_pages = array(

  'contact',
  'about',

);

$page = $HTTP_GET_VARS['page'];

if ( !$page )
{
  // Your index page here

  include( 'index.htm' );
}
else
{
  // Other page

  if ( in_array( $page, $my_pages ) )
  {
    // load the page
    include( $page . '.htm' );
  }
  else
  {
    // page doesn't exist
  }
}

?>

Link to comment
https://forums.phpfreaks.com/topic/82516-solved-isset-help/#findComment-419501
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.