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.
$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:
if "page" is the only get variable, you can use if(!isset($_GET[page])) { // display the table } else, use the $_SERVER[QUERY_STRING] varaiable
if( !$_GET['page'] ) { echo $table; } else { echo 'You may not view this table as you\'re not on the correct page!'; } PHP:
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,
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
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
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.
$_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,
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:
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,
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:
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,
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.
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,
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
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,