We help IT Professionals succeed at work.

Passing pages and GET variables to that page within a GET Variable

epiphone32
epiphone32 asked
on
189 Views
Last Modified: 2013-12-13
I currently load pages into divs by the following
//index.php
<div id='content'>
   if (!isset($_GET['page'])) { $PAGE = 'updates.php'; }
   if (!file_exists($PAGE)) { echo "<strong>$PAGE</strong>&nbsp;not found.<br>"; }
   else { include ($PAGE); }
?>

So I have a link similar to    <a href='index.php?page=media/music.php'>Music</a>

This causes the the music page to be loaded into the content div in  index.php

What I would like to do, is be able to pass variables to the requested page
so something like
<a href='index.php?page=media/music.php?artist=Neil Young&album=Harvest'>Neil Young - Harvest</a>
That way I could do
   $artist = $_GET['artist'];
   $album = $_GET['album'];
within the music.php page.

I have developed the following method to do so...
<a href='index.php?page=media/music.php|artist=Neil Young|album=Harvest'>Neil Young - Harvest</a>
Then within music.php
 
  $STR = $_GET['page'];
   echo "$STR<br>";
   $VARS = explode("|", substr($STR, stripos($STR, "?"), strlen($STR)));
   foreach ($VARS as $v) {
      //echo "--v: $v<br>";
      if ($VARS[0] == $v) { $PAGE = $v; }
      if (stripos($v, "artist=") !== false) { $ARTIST = substr($v, stripos($v, "=") + 1, strlen($v)); }
      if (stripos($v, "album=") !== false) { $ALBUM = substr($v, stripos($v, "=")+1, strlen($v)); }
   }  
   if (isset($PAGE) && isset($ARTIST) && isset($ALBUM)) {
      echo "PAGE:   $PAGE<BR>";
      echo "ARTIST: $ARTIST<BR>";
      echo "ALBUM:  $ALBUM<BR>";  
   }

<div id='content'>
   if (!isset($PAGE)) { $PAGE = 'updates.php'; }
   if (!file_exists($PAGE)) { echo "<strong>$PAGE</strong>&nbsp;not found.<br>"; }
   else { include ($PAGE); }
?>


Is there a better way to do this.   I would prefer not to serialize.   Like I said the prefered method would be
GET.   Keep in mind that the page is actually called by a include method.





Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
What was I thinking, I new that.   Well I guess I created an alternative method.
Thanks for the help.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.