CodeIgniter Forums
How would I write this PHP function so CI can be recognized? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How would I write this PHP function so CI can be recognized? (/showthread.php?tid=48066)



How would I write this PHP function so CI can be recognized? - El Forum - 01-03-2012

[eluser]qpixo[/eluser]
I have this URL: http://www.example.com/name/pageID


I want to store pageID into session assuming it's $this->uri->segment(2);
CI doesn't recognize _GET

How would I write this function so CI can recognize the syntax?



Code:
function checkPageID() {
    // 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 ( 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']];
    }
}