Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Coding-question: how to get filename out of URL for if-else-code?


Andreas2003

Recommended Posts

Hi there,

 

got a small problem:

I have to set a variable, but case-sensitive.

The first case is, when the main site of oscommerce "index.php" is being displayed.

The other case is, when the product page "product_info.php" is being displayed.

 

How can I find out, what the current site/page/filename is ?

Can I use something around $_SERVER["HTTP_HOST"] or $_SERVER["REQUEST_URI"] or something like that ?

$SERVER["SCRIPT_FILENAME"] brings up the filename, but the whole path is included.

I only need the filenname.

 

How can I handle that?

 

Thanks for your help

Regards

Andreas

 

 

Update:

sorry, posted too quickly.

Found the solution and managed it with $_SERVER["SCRIPT_NAME"]

Link to comment
Share on other sites

Another method:

 

  switch ( basename($PHP_SELF) ) {

case FILENAME_DEFAULT:

/* code for action on index.php */

	break;

case FILENAME_PRODUCT_INFO:

/* code for action on product_info.php */

	break;

default: 

/* code for action if no other cases are matched */
 }

If you only have two possibles an "if ... else" is great.

 

For more than that I always use the "switch".

:)

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...