我有网址细分: http://www.site.com/loadContent/contact/4
我想在浏览器地址栏中隐藏ID 4: http://www.site.com/loadContent/contact
联系人和4人都是动态加载
如何在我的代码中执行此操作?
更新:
我必须将$ pageID作为第二个参数
我有一个生成菜单列表项的功能:
function buildListItem($item) {
$urlItemName = url_title($item->name, 'dash', TRUE);
$urlCatID = ($item->cat_id);
$url = base_url() . $urlItemName . "/". $urlCatID;
if ($urlItemName == 'blog') {
$blog = "http://blog.tumblr.com";
return anchor($blog, strtoupper($item->name), 'target="_blank"');
} else {
return active_anchor($url, strtoupper($item->name));
}
}
public function loadContent($name, $pageID) {
$data['title'] = $this->tabPageData;
$data['tabMenu'] = $this->model->getAllMenuItems();
$data['links'] = $this->model->getLinksURLIcon();
$pageName = array('portfolio-1', 'portfolio-2');
// Store pageID within Session
//$sessionPageID = $this->session->set_userdata($this->uri->segment(2));
// Check if $name is in array pageName, get the page content and its name
if (in_array($name, $pageName)) {
$data['tabPageContent'] = $this->model->getPageContentByPageID($pageID);
$data['pageName'] = $this->model->getPageNameByID($pageID);
} elseif ($name == 'contact') {
// load Contact page
$data['tabContact'] = $this->model->getContactByPageID($pageID);
}
$this->load->view('content', $data);
}
答案 0 :(得分:1)
您的选择:
[编辑]
合理的通用代码 - 应该适用于大多数网页
<?
session_start();
if ( count ( $_GET ) )
{
$_SESSION['__get'] = $_GET;
header( 'Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] );
exit();
}
elseif ( array_key_exists( '__get', $_SESSION ) && count( $_SESSION['__get'] ) )
{
$_GET = $_SESSION['__get'];
$_SESSION['__get'] = array();
}
var_dump ( $_GET );
注意:底部的var_dump将在没有任何URL参数的页面上显示$ _GET。
注意:这是一次性的。脚本的第二次重新加载将显示$ _GET已被清空。如果您不想这样做,请移除$_SESSION['__get'] = array();
块中的elseif
。
<强> [编辑] 强>
更好的代码包含函数和每页GET参数范围(使用$_SERVER['PHP_SELF']
)
content-type:text / plain是为了让var_dump更容易阅读,仅此而已。
<?
// no-get.php
session_start();
header( 'content-type: text/plain' );
noGet();
var_dump( $_GET );
forgetNoGetPage();
var_dump( $_GET );
/**
* noGet - saves $_GET values to $_SESSION and redirects to same page
* @requires Session to be started
*/
function noGet()
{
// check count to see if there are fresh variables being passed to the script
// if there are, we overwrite any existing page variables in the session
// if we didn't do this, we could never pass new variables on the url to our scripts
if ( count ( $_GET ) )
{
$_SESSION['__get'][$_SERVER['PHP_SELF']] = $_GET;
header( 'Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] );
exit();
}
elseif (
array_key_exists( '__get', $_SESSION ) &&
array_key_exists( $_SERVER['PHP_SELF'], $_SESSION['__get'] ) &&
count( $_SESSION['__get'][$_SERVER['PHP_SELF']] )
)
{
$_GET = $_SESSION['__get'][$_SERVER['PHP_SELF']];
}
}
/**
* forgetNoGetPage - removes a page's $_GET values from the session and optionally redirects to the current page.
* @param String The page to remove entries for
* @param Bool Redirect after remove?
*/
function forgetNoGetPage( $page = null, $redirect = false )
{
if ( $page === null )
{
$page = $_SERVER['PHP_SELF'];
}
unset( $_SESSION['__get'][$page] );
if ( $redirect )
{
header( 'Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] );
}
}
答案 1 :(得分:1)
您必须首先获取身份证号码并保存在$_SESSION
中,并且在这项工作中,您使用preg_match给出一个没有身份证号码的网址字符串。
最后你重定向url使用<?php header("location: ". $URL") ?>