I do not want to show a table if it is index.php

Discussion in 'PHP' started by baris22, Oct 25, 2008.

  1. #1
    Hello all,

    I want to show a table if the page is index.php but i do not want to show that table if the page is different than that like:

    index.php?page=1
    index.php?page=2
    index.php?page=3
    and so on...

    How can i do this?

    Thank you everybody.
     
    baris22, Oct 25, 2008 IP
  2. Agent_Smith

    Agent_Smith Well-Known Member

    Messages:
    890
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    145
    #2
    $page = $_REQUEST['page'];
    
    if($page == 1)
    {
    
        // do page 1
    
    }
    else if($page == 2)
    {
    
        //do page 2..
    
    }
    else if($page == 3)
    {
    
        //have a guess
    }
    else
    {
        //your index page and everything else :)
    }
    PHP:
     
    Agent_Smith, Oct 25, 2008 IP
  3. neran

    neran Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    if "page" is the only get variable, you can use

    if(!isset($_GET[page]))
    {
    // display the table
    }

    else, use the $_SERVER[QUERY_STRING] varaiable
     
    neran, Oct 25, 2008 IP
  4. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    switch($_GET['page']) {
    default:
    //show index
    break;
    case "1":
    //page = 1
    break;
    }
     
    Kyosys, Oct 25, 2008 IP
  5. Calon

    Calon Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    if( !$_GET['page'] ) { 
         echo $table;
    } else { 
         echo 'You may not view this table as you\'re not on the correct page!';
    }
    
    PHP:
     
    Calon, Oct 25, 2008 IP
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    All the above posts will not work. This will work for what you want:

    
    if($_SERVER['REQUEST_URI'] == '/index.php'){
     echo 'Table';
    }
    
    PHP:

    It will only show the table on index.php and not on index.php?getvars

    Peace,
     
    Barti1987, Oct 25, 2008 IP
  7. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    i tried on local but it did not work. it is not displaying anything whether it is index.php or index.php?page=1

    thanks
     
    baris22, Oct 25, 2008 IP
  8. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Stop being such a smartass and read CAREFULLY what he wanted to do

    What he needs is one of our solutions. Personally, I prefer mine because of the switch, but that's up to him
     
    Kyosys, Oct 26, 2008 IP
  9. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #9
    I'm going to go out on a limb here, I'm not completely sure what you mean baris. :)

    if(empty($_SERVER['QUERY_STRING']))
    {
       // show table
    }
    else
    {
       // don't show table
    }
    Code (markup):
    If there's any GET variables, it will trigger.
     
    joebert, Oct 26, 2008 IP
  10. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #10
    $_SERVER values differ on the type of server. Follow these steps:

    Enter this code on a blank page:

    
    print_r($_SERVER);
    
    PHP:
    Then enter the page as page.php
    Then enter it again as page.php?ter=e

    Display the results here and I'll show you how to do it.

    Basically, you want to see which $_SERVER value changes and how.

    Peace,
     
    Barti1987, Oct 26, 2008 IP
  11. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #11
    it says

    
    
    Array ( [HTTP_ACCEPT] => image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */* 
    
    [HTTP_REFERER] => http://localhost/son/index.php 
    
    [HTTP_ACCEPT_LANGUAGE] => en-us 
    
    [HTTP_UA_CPU] => x86 
    
    [HTTP_ACCEPT_ENCODING] => gzip, deflate 
    
    [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.2) 
    
    [HTTP_HOST] => localhost 
    
    [HTTP_CONNECTION] => Keep-Alive 
    
    [PATH] => C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem 
    
    [SystemRoot] => C:\WINDOWS
    
    [COMSPEC] => C:\WINDOWS\system32\cmd.exe 
    
    [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
    
    [WINDIR] => C:\WINDOWS 
    
    [SERVER_SIGNATURE] => Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80 
    
    [SERVER_SOFTWARE] => Apache/2.2.8 (Win32) PHP/5.2.6 
    
    [SERVER_NAME] => localhost 
    
    [SERVER_ADDR] => 127.0.0.1
    
    [SERVER_PORT] => 80 
    
    [REMOTE_ADDR] => 127.0.0.1
    
    [DOCUMENT_ROOT] => C:/AppServ/www 
    
    [SERVER_ADMIN] => admin@gmail.com
    
    [SCRIPT_FILENAME] => C:/AppServ/www/son/index.php 
    
    [REMOTE_PORT] => 2350 
    
    [GATEWAY_INTERFACE] => CGI/1.1 
    
    [SERVER_PROTOCOL] => HTTP/1.1
    
    [REQUEST_METHOD] => GET 
    
    [QUERY_STRING] =>
    
    [REQUEST_URI] => /son/index.php 
    
    [SCRIPT_NAME] => /son/index.php 
    
    [PHP_SELF] => /son/index.php
    
    [REQUEST_TIME] => 1225032314 
    
    [argv] => Array ( ) 
    
    [argc] => 0 ) 
    
    
    PHP:
     
    baris22, Oct 26, 2008 IP
  12. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #12
    Then use the same code I gave you, except instead of /index.php you need to use:

    /son/index.php

    as REQUEST_URI shows it.

    If you try to access the page via:

    http://site.com/son/index.php?var=t

    You will see REQUEST_URI changing to:

    /son/index.php?var=t

    Chances are when you upload it to the internet server, you might have to change it back to /index.php if the index.php is on the main root.

    Peace,
     
    Barti1987, Oct 26, 2008 IP
    baris22 likes this.
  13. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #13
    index.php?page=2

    
    
    Array ( [HTTP_ACCEPT] => */* [HTTP_ACCEPT_LANGUAGE] => en-us [HTTP_UA_CPU] => x86 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_USER_AGENT] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; InfoPath.2) [HTTP_HOST] => localhost [HTTP_CONNECTION] => Keep-Alive [PATH] => C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem [SystemRoot] => C:\WINDOWS [COMSPEC] => C:\WINDOWS\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH [WINDIR] => C:\WINDOWS [SERVER_SIGNATURE] => 
    
    Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80 
    
    [SERVER_SOFTWARE] => Apache/2.2.8 (Win32) PHP/5.2.6 [SERVER_NAME] => localhost [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => C:/AppServ/www [SERVER_ADMIN] => admin@gmail.com [SCRIPT_FILENAME] => C:/AppServ/www/son/index.php [REMOTE_PORT] => 2377 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => page=2 [REQUEST_URI] => /son/index.php?page=2 [SCRIPT_NAME] => /son/index.php [PHP_SELF] => /son/index.php [REQUEST_TIME] => 1225032793 [argv] => Array ( [0] => page=2 ) [argc] => 1 ) 
    
    
    PHP:
     
    baris22, Oct 26, 2008 IP
  14. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #14
    Yes, you can can see that REQUEST_URI changed to /son/index.php?page=2. Just incase you missed it, I just posted right after the 11th post.

    Peace,
     
    Barti1987, Oct 26, 2008 IP
  15. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #15
    I don't understand why you're using REQUEST_URI instead of QUERY_STRING.
     
    joebert, Oct 26, 2008 IP
  16. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #16
    
    
    if($_SERVER['REQUEST_URI'] == '/son/index.php'){ echo 'Table';}
    
    
    PHP:
    worked.

    I tried:

    http://localhost/son/index.php
    son/index.php
    index.php

    They did not work.

    Thank you for your help.
     
    baris22, Oct 26, 2008 IP
  17. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #17
    Oh ok. This must be for an include or something.
     
    joebert, Oct 26, 2008 IP
  18. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #18
    The OP question was specific in regards to index.php (i am not sure about other pages, maybe there aren't none).

    If he wants to include other pages, then he must use the QUERY_STRING.

    Peace,
     
    Barti1987, Oct 26, 2008 IP
  19. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #19
    based from the OP's question, the script should probably just detect if $_SERVER['QUERY_STRING'] is set or is not empty, if it is, then dont show the table
     
    serialCoder, Oct 26, 2008 IP
  20. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #20
    But then if you do, you will display the table on anotherpage.php and so on. Which isn't probably the case.

    Then again, maybe he did want that, but I don't know.

    Peace,
     
    Barti1987, Oct 26, 2008 IP