Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:06:42+00:00 2026-06-08T19:06:42+00:00

All I am looking for is when the below code is run and the

  • 0

All I am looking for is when the below code is run and the Albums or the Music links are clicked it posts to the same page, correct? hence the url changes and add the href on the end of it depending on the link clicked. Well how can I call the following when the link is clicked:

<?php echo 'Albums';?>

Original code:

if(isset($_GET['username']) === true && empty($_GET['username']) === false){
$username       = $_GET['username'];

if(user_exists($username) === true){
$user_id        = user_id_from_username($username);
$profile_data   = user_data($user_id, 'first_name','last_name','email');
?>

    <h1><?php echo $profile_data['first_name']; ?>'s Yor Page</h1>




<div id="navWrapper">


    <ul>
        <li>
            <a href="#"><img src="uploads/profile/blank_profile.gif" width="150" height="150" id="blank_profile"></a>
        </li>

        <nav>
            <ul>
                <li>
                    <a href="?albums">Albums</a>
                </li>
                <li>
                    <a href="?music">Music</a>
                </li>
            </ul>
        </nav>
    </ul>

</div>
<?php
}else{
    echo 'Sorry, that user doesn\'t exist';
}
}else{
header('Location: index.php');
exit();
}

include 'includes/overall/overall_footer.php';
?>

Now I have the link setup when clicked it returns yorpage.com/lr/username?albums, how can I call a php function or statement when I click on this link and go to url yorpage.com/lr/username?albums?

So a simple echo would be fine for demonstration purposes just to get a return on the click is what I am looking for. If you need more info, I don’t think you do I’m not asking to code this for me I can return the images or albums etc. I just want to find out how to handle that link being clicked and returning a simple echo when Albums or Music links are clicked. Thank You.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:06:44+00:00Added an answer on June 8, 2026 at 7:06 pm

    I’m a little lost but as I understood, your question is: How can I pass arguments in the url so that when I go to the URL http://www.example.com/username/albums it goes to albums right?

    here’s an example of something similar:

        if (isset($_GET['page'])) {
            $pageArgs = explode('/', $_GET['page']);
            if(isset($pageArgs[0])) {
                $username = $pageArgs[0];   
            } else {
                header('Location: index.php');
                exit();     
            }
            $action = (isset($pageArgs[1])) ? $pageArgs[1] : false;
            switch($action)
            {
                case 'albums':
                    print 'These are my albums <br/>';
                    break;
                case 'music':
                    print 'This is my music! <br/>';
                    break;
    
                default:
                    print '
                        <nav>
                            <ul>
                                <li><a href="'.$username.'/albums">Albums</a></li>
                                <li><a href="'.$username.'/music">Music</a></li>
                            </ul>
                        </nav>';
                    break;
            }
        }
    

    Adapt this to your needs…

    NOTE: Please note that I changed the argument to page instead of username so you have to update your rewrite mod rules. I also used / to separate page “arguments”. You can use “?” (i think, not sure) if you prefer…


    This following a simple MVC

    index.php

    // Find which page is requested
    $pageIDs = pageSelector();
    // namespaced pages. You can change to real namespaces with:
    // $mPage = '\\Page\\' . $pageIDs[0];
    $mPage = 'Page_' . $pageIDs[0];
    array_shift($pageIDs);
    
    // Path to Template file (the static elements common to all pages like
    // header, footer, logo, navigation, etc...
    $templatePath = 'templates/my_template.html';
    
    if(!empty($pageIDs))
        $pageArgs = $pageIDs;
    else
        $pageArgs = false;
    
    //create Page Object, the dynamic content divided by sections
    //for instance, content, columnA, columnB   
    $page = new $mPage($pageArgs);
    
    $template = new Template($templatePath, $page);
    
    //Here's an example of a section
    $template->addSection('subNavigation');
    
    print $template;
    
    // PageSelector Function
    function pageSelector()
    {
        if (isset($_GET['page'])) {
            $pIDs = explode('/', $_GET['page']);    
        } else {
            $pIDs = array('home');
        }
        $pagePath = 'pages/' . $pIDs[0] . '.php';
        if (file_exists($pagePath)) {
            require_once($pagePath);
            return $pIDs;
        } else {
            $pagePath = 'pages/home.php';
            require_once($pagePath);
            return array('home');
        }
    }
    
    
    
    //Template Object
    class Template
    {
        private $path, $page;
        private $sections = array('content');
    
        public function __construct($tPath, $page)
        {
            $this->path = $tPath;
            $this->page = $page;
        }
    
        public function addSection($newSectionName)
        {
            $this->sections[] = $newSectionName;
        }
    
        public function __toString()
        {
            $html = file_get_contents($this->path);
            foreach($this->sections as $section) {
                $html = str_replace('[%%'.$section.'%%]', $this->page->show($section), $html);
            }
            return $html;
        }
    }
    

    file pages/home.php

    class Page_home
    {
        public function __construct($args) {}
    
        public function show($section)
        {
            switch($section)
            {
                case 'content':
                    return 'this is my main page';
                break;
    
                default:
                    return '';
                break;
            }
        }   
    }
    

    file pages/user.php

    class Page_user
    {
        private $subPage;
        public function __construct($args)
        {
            if(isset($args[0])) 
                $this->username = $args[0];
            else {
                $this->username = false;
                return;
            }
            if(isset($args[1]))
                $this->subPage = $args[1];
            else {
                $this->subPage = false;
                return;
            }
    
        }
    
        public function show($section)
        {
            if($this->username)
            {
                switch($section)
                {
                    case 'content':
                        $otp  = 'My username is ' . $this->username . '<br/>';
                        $otp .= $this->showSubPage();
                        return $otp;
                    break;
    
                    case 'subNavigation':
                        return $this->nav();
                    break;
    
                    default:
                        return '';
                    break;
                }   
            } else {
                return 'username not found!';
            }
        }
    
        protected function nav()
        {
            return
            '<nav>
                <ul>
                    <li><a href="user/'.$this->username.'/albums">Albums</a></li>
                    <li><a href="user/'.$this->username.'/music">Music</a></li>
                </ul>
            </nav>';    
        }
    
        protected function showSubPage()
        {
            switch($this->subPage)
            {
                case 'albums':
                    return 'These are my albums <br/>';
                    break;
                case 'music':
                    return 'This is my music! <br/>';
                    break; 
            }
        }
    }
    

    templates/my_template.html

    <!DOCTYPE HTML>
    <html>
    <head>
    </head>
    <body>
        <div id="mainNav">myLink | Go | Here</div>
        <nav id="subNav">[%%subNavigation%%]</nav>
        <div id="content">[%%content%%]</div>
        <footer>my (c) copyright notice</footer>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running the following code, the filenames of all files below C:\Test are printed.
I was looking all over and couldn't get a direct and clear answer. Is
I have been looking all over the internet and i found some good guides
I have been looking all over for this. I have two seperate prpt files
I've been looking all over the internet for a solution to the following error;
I've been looking all over for a simple example of how to have an
So, I've been looking all over. I can't find anywhere that talks about specifically
I am totally new to math/numerical analysis programming and I was looking all over
Okay, I've been looking all over the web to find a solution but I
Possible Duplicate: Register the Android App with C2DM so, I've been looking all over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.