Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Body ID code

Featured Replies

Hi,

 

I have a small piece of PHP code that i am using...

 

<body id="<?= basename($_SERVER['PHP_SELF'], ".php")?>">

 

Which works great, apart from the fact that the body id once the PHP has been executed is called 'index' (well for the homepage), which im not really after! I would much rather have it body id="home" , is there anyway to tweak this code so it would see the first page is index.php but give it an id of 'home' and then do the other pages as normal??

Use an array to map with the id names you want

 

 

something like this...

var ids = ['index.php' => 'home', 'contact.php' => 'contact'];

<body id="<?= ids[basename($_SERVER['PHP_SELF'])] ?>">

EDIT: didn't see yours Thomas.

 

<?php
if (basename($_SERVER['PHP_SELF'], ".php") == 'index') {
  $id = "home";
}
else {
  $id = basename($_SERVER['PHP_SELF'], ".php");
}
?>

<body id="<?php echo $id;?>">

 

That should work although its not tested.

  • Author

EDIT: didn't see yours Thomas.

 

<?php
if (basename($_SERVER['PHP_SELF'], ".php") == 'index') {
  $id = "home";
}
else {
  $id = basename($_SERVER['PHP_SELF'], ".php");
}
?>

<body id="<?php echo $id;?>">

 

That should work although it’s not tested.

 

Cheers scaz, that worked a treat!! Top man!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.