By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

embedded links with php

P: 14
hello,

is it possible to do embedded links from a php script?

Check out the code below, when I send the test case to the switch, it will not go to the embedded link #clarence2

Any thoughts?

Thanks,
Tim

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $location=$_GET['location']; if (empty($location)) { $location='index'; } changelocation($location); function changelocation($location) { include ('header.php'); echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="750">';echo '<tr>';echo '<td width="750"  align="center" valign="top">';
  4.  
  5. switch ($location) 
  6. {
  7. case 'index':
  8. include ('home.php'); break; 
  9.  
  10. case 'artists':
  11. include ('artists.php'); break; 
  12.  
  13. case 'artwork':
  14. include ('artwork.php'); break; 
  15.  
  16. case 'location':
  17. include ('location.php'); break; 
  18.  
  19. case 'contact':
  20. include ('contact.php'); break; 
  21.  
  22. case 'aboutus':
  23. include ('aboutus.php'); break;
  24.  
  25. case 'test':
  26. include ('http://www.hermitagegallery.com/artists/test.php#clarence2'); break; 
  27.  
  28. } include ('footer.php'); }
  29. ?>
  30.  
Oct 2 '07 #1
Share this Question
Share on Google+
5 Replies


ak1dnar
Expert 100+
P: 1,584
Sorry you can't call for a "onpagelink" or "bookmarks" on the page, but the main page will display. if you need to display the page with the onpage link use headers
Oct 2 '07 #2

Motoma
Expert 2.5K+
P: 3,235
Let me step back and explain a little about the way includes work:

The moment the PHP interpreter encounters and include statement, the PHP interpreter stops processing the current PHP page, and begins executing the code located in the included file. An easy way to imagine this is to say that the entire body of code located in the included PHP file is copied and pasted at that exact point in the code where the include statement is located.

When you call and Include statement, you are not directing the browser; everything happens server-side, and the end user remains at the parent page.

As my compatriot ajaxrand stated, the proper way to redirect a user is to issue a header() call. The only caveat of doing so is that you cannot print any HTML before doing so.
Oct 2 '07 #3

P: 14
So this will not work then right? Or do I need to move my switch statement around?

I get what your saying but if I just have a redirect statement from a header statement, it will just redirect me to the page I specify without mainting the php script I use for the index, to put my own Header.php and Footer.php files below

just a little lost with headers, since I can get them to work if I put a header redirect before all the code, but it does not maintain the code.

Thanks!
Oct 2 '07 #4

P: 14
Not sure if headers are going to do what I need. Basically I need to have a case call the page but go to a bookmark/embedded link in the page (mainly cause I am going to have a page for one artist, but some artists have multiple art pieces, so I need an embedded link so on the art page, when they click on a specific piece of art, it takes them to that embedded link, not just the top of that page). I need to be able to display a Header.php (links and toolbar) before I run switch statement, which in turn means html is already ran defeating the header statement and getting me an error.
Oct 2 '07 #5

P: 14
I think I may have a solution.

For every piece of art, I will create seperate pages. When someone wants to view all the art created by an artist by clicking the link, within the switch case for that artist, I will have a new include for each piece of art.

Under the art section, when they want to view just one piece of art, i will have a seperate switch statement just for that piece of art.

So the art wont be all on one page for each artists, so I wont need to use embedded links or header()s.

Any thoughts if this is a bad idea?

Thanks!
Oct 2 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.