A simple request - 200pts for it

Status
Not open for further replies.

randomize

New Member
Messages
674
Reaction score
0
Points
0
Hey

I want someone to tell me how you do the following:

index.php?page=staff

well along those lines,

I wish someone to give the code, and explain in "lamens" terms, (Simplistic if you must) so that I can understand it easily, as I am a complete and utter n00b at PHP.

I offer to you 200pts for this

Regards,
Randomize
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
This is saying the pages would be under the pages folder and the link would be

index.php?page=FILE
file is the name of the file in the page you want to display.
Staff would be your default page if you didnt do index.php?page=
as it says &page= "staff";
PHP:
<?php 
if ($_GET['page']) { $page = "staff"; } else { $page = $_GET['page']; } 
include ("pages/$page.php"); 
?>


or

PHP:
<?php 

$page = $_GET['page']; 

  if (!$page) { 
      $page = "staff"; 
   } else { 
      $page = str_replace(":", "", $page); 
      $page = str_replace( "/", "", $page); 
      $page = str_replace( ".", "", $page); 
      $page = str_replace( "http", "", $page); 
      $page = str_replace( "www", "", $page); 
   } 

   include ($page .".php"); 
?>


or
PHP:
<?php 
  if (!$_GET['page']) { 
      $page = "staff"; 
   } else { 
      $page = $_GET['page']; 
   } 

   include ($page .".php"); 
?>

ps nedren helped me with this long time ago this has to be right...
 
Last edited:

chris218

New Member
Messages
130
Reaction score
0
Points
0
I told you this before and you never paid me the credits..

You can also very simple way do this:

Code:
if ( $_GET['page'] == 'staff' )
{

}

and this if you have many pages, and a default (if page is not given..)

I will give page=staff and page=admin

Code:
if( isset($HTTP_GET_VARS['staff']) || isset($HTTP_POST_VARS['staff']) )
{
    $staff = ( isset($HTTP_GET_VARS['staff']) ) ? $HTTP_GET_VARS['staff'] : $HTTP_POST_VARS['staff'];
    $staff = htmlspecialchars($staff);
}
else 
{
    $staff = "";
}

switch( $staff )
    {    
         case "staff":
        // code for staff page here
       break;

         case "admin":
        // code for admin page here
       break;

      default:
     // code for default page here
    break;
}
 

randomize

New Member
Messages
674
Reaction score
0
Points
0
is this working then?

http://www.sapiencreations.x10hosting.com/pdogdis/switch.php

Code:
<?php 
include("../ads.php");
if( isset($HTTP_GET_VARS['team']) || isset($HTTP_POST_VARS['team']) )
{
    $team = ( isset($HTTP_GET_VARS['team']) ) ? $HTTP_GET_VARS['team'] : $HTTP_POST_VARS['team'];
    $team = htmlspecialchars($team);
}
else 
{
    $team = "";
}
switch( $team )
    {    
         case "team1":
        echo("this is team1 page");
       break;
         case "team2":
        echo("bah1");
       break;
      default:
     echo("bah");
    break;
}
?>

This should work, as it is exactly what you told me to put? Was I right to use echo? or should it just be html code?

Points are being sent to both of you however, cuz you told me!

However when you go to http://sapiencreations.x10hosting.com/pdogdis/switch.php?=team1

I get the same response as from switch.php!
 
Last edited:

chris218

New Member
Messages
130
Reaction score
0
Points
0
randomize said:
is this working then?

http://www.sapiencreations.x10hosting.com/pdogdis/switch.php

Code:
<?php 
include("../ads.php");
if( isset($HTTP_GET_VARS['team']) || isset($HTTP_POST_VARS['team']) )
{
    $team = ( isset($HTTP_GET_VARS['team']) ) ? $HTTP_GET_VARS['team'] : $HTTP_POST_VARS['team'];
    $team = htmlspecialchars($team);
}
else 
{
    $team = "";
}
switch( $team )
    {    
         case "team1":
        echo("this is team1 page");
       break;
         case "team2":
        echo("bah1");
       break;
      default:
     echo("bah");
    break;
}
?>

This should work, as it is exactly what you told me to put? Was I right to use echo? or should it just be html code?

Points are being sent to both of you however, cuz you told me!

However when you go to http://sapiencreations.x10hosting.com/pdogdis/switch.php?=team1

I get the same response as from switch.php!
thats because you havn't put team=team1

Also.. you can use echo or you can include html by doing the bellow or you can do number 2...

Code:
include('some_html_file.html');

Two
?>
HTML HERE
<?php

tells server to stop parsing php, so it parses html until you turn php back on with <?php
 

mikel2k3

New Member
Messages
748
Reaction score
0
Points
0
oh balls im well confused... i suppose it would be a good thing for me to learn though
 

nightscream

New Member
Messages
948
Reaction score
0
Points
0
I did it like this
Put this in your index.php
PHP:
<?php
 $id = $_REQUEST['page'];
switch($page) {
default: include('index2.php');
 break;
case "News": include('news.php');
break;
 case "Staff": include('staff.php');
break;
 case "Links": include('links.php');
 }
?>
and in your nav put this
default will be index2.php
index.php?page=News for news
index.php?page=Staff for staff
 
Last edited:

randomize

New Member
Messages
674
Reaction score
0
Points
0
woo thank you chris,

I sent you the points last night!

Regards,
Randomize

EDIT:

I got it working under
http://sapiencreations.x10hosting.com/pdogdis/switch.php?team=ceo1
http://sapiencreations.x10hosting.com/pdogdis/switch.php?team=team2

However, I am implementing it into a page, and it uses php includes

so which do I put it in and which do I link it too?

the files:

team_content.php
ourteam.php

ourteam.php is the main page that you go to in the navigation, and that page uses an include to team_content.php

Basically I want to put it in there, so that I can have ourteam.php?team=ceo1

so where do I place the script?
 
Last edited:
Status
Not open for further replies.
Top