douyun1950 2019-02-13 04:42
浏览 44

在获取页面名称以进行更新时遇到问题

Ok, so I have been coding a marketplace script for my website in I been trying to get theses links to work, For some reason when a user clicks on the links the page name doesn't update to the new page that they're viewing the rest of the page update but not the page name. So my links show like this dashboard.php?account=withdraws. on the website the dashboard pagename still shows in never updates. So I have included my PHP code of the dashboard I hope somebody can help me resolve this.

Here's the top of the dashboard

<?php
// Seddeo Page System - Customer Dashboard
DEFINE("IN_SEDDEO", 1);

$pageName = "Dashboard";
$body = "customer-dashboard";

require_once('inc/config.php');
require_once('inc/header.php');

$account = $_GET['account'];
$action = isset($_GET['action']) ? $_GET['action'] : '';

// If no login go to login page
if(!$user->is_logged_in()){ 
    header('Location: signin.php?action=nologin'); 
}
if(isset($account)) {
     require_once("{$account}.php");
} else {
?>

And here's the bottom of the dashboard

<?php require_once('inc/footer.php'); ?>
<?php } ?>

I have also included my PHP code of the withdraw page.

Here's the top of the withdraw page

<?php
// Seddeo Page System - Customer Dashboard
DEFINE("IN_SEDDEO", 1);

$pageName = "Account Settings";
$body = "dashboard-settings";

require_once('inc/config.php');
require_once('inc/header.php');

$account = $_GET['account'];
$action = isset($_GET['action']) ? $_GET['action'] : '';

// If no login go to login page
if(!$user->is_logged_in()){ 
    header('Location: signin.php?action=nologin'); 
}
?>   

Very bottom of the page

<?php require_once('inc/footer.php'); ?>

So I hope somebody can help me resolve this issue, thank you.

Ok so here's my header file

<?php
// Create a session only if we don't have one 
if (session_status() !== PHP_SESSION_ACTIVE) 
{ session_start(); 
}

// User data
$myID      = ($_SESSION["userID"])      ?: null; 
$ownerIP      = ($_SERVER["REMOTE_ADDR"])      ?: null; 
$myUser      = ($_SESSION["username"])      ?: null; 

if(!empty($myUser)) {
    $db->update('UPDATE members SET lastActive = NOW() WHERE username = ?', array($myUser)); 
    $info = $db->fetch("SELECT * FROM members WHERE username = ?", array($myUser));
    $rank = $info['rank'];
    $regIP = $info['ownerIP'];
    $lastLoginIP = $info['lastLoginIP'];
    $id = $info['memberID'];
    $my_Avatar = $info['my_Avatar'];
    $myMembership = $info['myMembership'];
    $account_type = $info['account_type'];
}

// Verified Page 
if(!DEFINED("IN_SEDDEO")) 
{ 
die("You cannot access this file directly."); 
}

if($account_type == 1) {
$isAccount = true;
} else {
$isAccount = false;
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">

    <!-- viewport meta -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="MartPlace - Complete Online Multipurpose Marketplace HTML Template">
    <meta name="keywords" content="app, app landing, product landing, digital, material, html5">


    <title>Seddeo - <?php echo $pageName; ?></title>

    <!-- inject:css -->
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/fontello.css">
    <link rel="stylesheet" href="css/jquery-ui.css">
    <link rel="stylesheet" href="css/lnr-icon.css">
    <link rel="stylesheet" href="css/owl.carousel.css">
    <link rel="stylesheet" href="css/slick.css">
    <link rel="stylesheet" href="css/trumbowyg.min.css">
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">
    <!-- endinject -->

    <!-- Favicon -->
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon.png">
</head>
  • 写回答

1条回答 默认 最新

  • dongli8979 2019-02-14 08:49
    关注

    So as far as i can see, the inc/header.php file is included BEFORE the account.php file.

    You will see that the $pageName variable is used in inc/header.php file.

    but the value of $pageName is only changed AFTER the the inc/header.php file is included... meaning that the value will ALWAYS be it's initial value, i.e: Dashboard

    In summary:

    dashboard.php
      \-> $pageName = 'Dashboard'
      \-> loads header.php
      \-> $pageName is still 'Dashboard'
      \-> <title> tag uses $pageName
      \-> load account.php
      \-> $pageName = "Account Settings" (which doesn't matter since it has already been used in header.php
    

    To solve your problem i would suggest add the following to dashboard.php

    BEFORE this line:

    require_once('inc/config.php');
    require_once('inc/header.php');
    
    $titles = [
     'dashboard.php' => 'Dashboard',
     'dashboard.php?account=update-account' => 'Account Settings'
    ];
    $pageName = isset( $titles[ $_SERVER['REQUEST_URI'] ] ) ? $titles[$_SERVER['REQUEST_URI'] ] : 'Dashboard'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line