Im a bit of a newbie to php, ive already got something working except i would like to be able to say if page = mypage.php (followed by anything) then print this

eg:

mypage.php?
mypage.php?&this_could_be_anything

what I am using now is:

<?php $myIndexPage = "index.php";
$myDomainName = "mydomain.com";
$_SERVER[HTTP_HOST] = strtolower($_SERVER[HTTP_HOST]);
if($_SERVER[REQUEST_URI]=="/".$myIndexPage or $_SERVER[REQUEST_URI]=="/".$myIndexPage."/" or $_SERVER[REQUEST_URI]=="/" or $_SERVER[REQUEST_URI]=="/?currency=EUR" or $_SERVER[REQUEST_URI]=="/?currency=GBP" or $_SERVER[REQUEST_URI]=="/?currency=USD"){
?>

you can see ive had to add the currency querystrings to the address... id like to be able to tell it if it begins with index.php as well as index.php with a querystring following it to print something different...

thanks

    Try using this instead:

    if(basename($_SERVER['PHP_SELF']) == 'index.php')

      tried that actually
      i thought it might work - but i have a rewrite on my htaccess that creates SEO friendly urls (with .html) and it wont grab those rewrote names... which is what i wish i would do

        Really? Doing a quick test on my server, PHP_SELF returned phpinfo.php though I was using phpinfo.html to access it.

        Hm... perhaps try doing this instead:

        if(basename($_SERVER['PATH_TRANSLATED']) == 'index.php')

        If that doesn't work, try sticking a phpinfo() on this rewritten page and looking through the various SERVER variables, such as $SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'], etc.

          well i thought this would work... but its not for some reason...

          if(($_SERVER['REQUEST_URI']=="/") && (isset($_GET['currency']))){
          echo 'Test';
          }

          which seems it would work from this url

          http://www.mydomain.com/?currency=USD

          because the below code does work...

          $get_variable = 'no querystring';
          
          if ( isset( $_GET['name'] ) ) {
          $get_variable = 'with name querystring';
          echo $get_variable;
          
          } elseif ( isset( $_GET['currency'] ) ) {
          $get_variable = 'with currency querystring';
          echo $get_variable;
          } else {
          
          echo $get_variable;
          }

          i even tried assigning a value if the querystring existed and doing this... with no joy

          if(($_SERVER['REQUEST_URI']=="/") && ($get_variable==1)){
          echo 'Test';
          }

          any ideas why this isnt working??

            ceddy wrote:

            which seems it would work from this url

            Uh... no it wouldn't. If the REQUEST_URI is '/', that means the client said something like this:

            GET / HTTP/1.0

            In other words, they went to http://www.mydomain.com/ . Now, if they went to http://www.mydomain.com/?currency=USD, then they said this to your server:

            GET /?currency=USD HTTP/1.0

            which means $_SERVER['REQUEST_URI'] would be.. yep, you guessed it: /?currency=USD .

            EDIT: It sounds like you need to do some simple debugging. If it's not working, examine the variables you're dealing with... i.e. echo $_SERVER['REQUEST_URI'] and make sure it is what you think it is.

              is there any way i can capture the querystring and create a variable with the whole sting in it?

              the thing is, the querystring can be random - considering my sessions on my site, i wont use only the currency, ill also use ?session=

              and the basename wont work because the basename for all my pages, my index page, my product listing and product info are all index.php, just different querystrings attached to my index.php (but with rewrite you could never tell)

              ive done some testing and cant figure out why the value wouldnt work though....

              if i do this:

              $get_variable = 0;
              
              if ( isset( $_GET['currency'] ) ) {
              $get_variable = 1;
              }

              which does work.. if i echo it will either say 0/1 correctly....

              why wont this line work that I am trying?

              if($_SERVER[REQUEST_URI]=="/random_page.php" && ($get_variable==1)){
              
                ceddy wrote:

                is there any way i can capture the querystring and create a variable with the whole sting in it?

                the thing is, the querystring can be random - considering my sessions on my site, i wont use only the currency, ill also use ?session=

                Do a [man]print_r/man on the $SERVER array - you'll find such useful items as $SERVER['QUERY_STRING'].

                ceddy wrote:

                why wont this line work that I am trying?

                Dunno - apparently one of those variables doesn't contain the value you think it does, so try debugging:

                if($_SERVER[REQUEST_URI]=="/random_page.php" && ($get_variable==1)) {
                    // do whatever
                } else { // DEBUG
                    echo 'REQUEST_URI: ' . $_SERVER['REQUEST_URI'] . '<br>'; // DEBUG
                    echo 'get_variable: ' . $get_variable; // DEBUG
                } // DEBUG

                  i did get this working last night, i thank you for your help.

                  $QSTRING = $_SERVER['QUERY_STRING']; 
                  
                  $myIndexPage = "index.php";
                  $myDomainName = "sensualamour.com";
                  $_SERVER[HTTP_HOST] = strtolower($_SERVER[HTTP_HOST]);
                  
                  if($_SERVER[REQUEST_URI]=="/".$myIndexPage or $_SERVER[REQUEST_URI]=="/".$myIndexPage."/" or $_SERVER[REQUEST_URI]=="/" or $_SERVER[REQUEST_URI]=="/?" . $QSTRING){
                  ?>
                  <b>Do stuff</b>
                  <?
                  }
                  
                    Write a Reply...