•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,493 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,677 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1864 | Replies: 22
![]() |
•
•
Join Date: Jan 2006
Posts: 28
Reputation:
Rep Power: 3
Solved Threads: 0
I understand how to use the basic include function in a .php page so that repetitive content (like a menu) can be coded in a separate file and then dynamically included in multiple pages. But I don't get how to use it so that a URL in a page can be clicked to load content into the original page with the hyperlink.
For example a page with a special offer that requires a disclaimer would use the following to link to a separate page:
I'm hoping to load that disclaimer right into the original page if someone wants to read it when they click on the link.
How can that be done with the PHP include function?
And can PHP be used in a .shtml page?
Thanks.
For example a page with a special offer that requires a disclaimer would use the following to link to a separate page:
<a href="disclaimer.html">click here to read the disclaimer</a>
I'm hoping to load that disclaimer right into the original page if someone wants to read it when they click on the link.
How can that be done with the PHP include function?
And can PHP be used in a .shtml page?
Thanks.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
look at this: www.banditssoftball.org/show.php
oh yeah, from what i know, php can be used in any type of file as long as the server is set up for it.
oh yeah, from what i know, php can be used in any type of file as long as the server is set up for it.
Last edited by kkeith29 : Sep 23rd, 2007 at 6:38 am.
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
Actually, kkeith29 example doesn't load new content in the original page; it just reloads the page with a parameter passed through the $_GET variable, and shows some text as a response of that parameter.
Since php is a server side script, which means it is processed on the server and only the result of the process is sent to the client (browser), in order to process any piece of php code (like an 'include' request), that piece of code must be passed through the server; you cannot execute php code inside the user browser; for that, you need to use a client side script (like javascript).
A simple approach to what you want is to insert in your page, from the beginning, in a hiddend block (div, p etc.), the piece of text that you want to show on click, and make a javascript that simply shows that block of text when you click the link.
If the block of text (or whatever it is) must be the result of a php script, than the only way you can insert that on the page on client side (without reloading the page) is through AJAX, which is, simply put, javascript communicating with the server (the php page in your case) without the page reload.
Since php is a server side script, which means it is processed on the server and only the result of the process is sent to the client (browser), in order to process any piece of php code (like an 'include' request), that piece of code must be passed through the server; you cannot execute php code inside the user browser; for that, you need to use a client side script (like javascript).
A simple approach to what you want is to insert in your page, from the beginning, in a hiddend block (div, p etc.), the piece of text that you want to show on click, and make a javascript that simply shows that block of text when you click the link.
If the block of text (or whatever it is) must be the result of a php script, than the only way you can insert that on the page on client side (without reloading the page) is through AJAX, which is, simply put, javascript communicating with the server (the php page in your case) without the page reload.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
sorry, i'm not stupid. I know how php works, and yes it does load new content into the original page. the text wasn't there before was it. By saying he wanted it in the original page, i think he means that he wanted the text to show up without have to go to a different page to view the content. If he means that it should show up without the page reloading then he should be more specific. Anyways, think if javascript is disabled. Neither javascript or AJAX would work, then your screwed. if you use my way, it always works.
Last edited by kkeith29 : Sep 23rd, 2007 at 7:02 pm.
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
Hey, kkeith29, don't take it so personally; I didn't meant you were stupid; I wasn't even replying to you, but to Syakoban; your solution is very good if you want to reload the page; I just understood something else from Syakoban post (to be more clear, I understood he wanted to load some content in the page without reloading the page) and I pointed out to him the differences so he can learn an choose what best suits him (or her
).
I am sorry if my post offended you. I asure you that wasn't my intention. Ok?
).I am sorry if my post offended you. I asure you that wasn't my intention. Ok?
•
•
Join Date: Jan 2006
Posts: 28
Reputation:
Rep Power: 3
Solved Threads: 0
•
•
•
•
he wanted the text to show up without have to go to a different page to view the content.
That's right! I've used another script that works this way w/cookies that based on number of visits to the home page, pulls in different content while still staying at the "home page". I am looking for that effect - reloading is not an issue.
I just started to try your sample code and am not getting it to work on the server yet. I took both pages you created as is (show.php and stuff.html) and simply wanted to get it working before making any changes. I uploaded in ASCII. I gave the original page a .php extension, but does the script need to be enclosed in <?PHP ?> tags? Can it be anywhere in the page? When I click the link I get no change except to the URL.
Mine is at http://ehydrant.com/show.php
Thanks.
Last edited by Syakoban : Sep 23rd, 2007 at 10:35 pm. Reason: fix
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
sorry about that, i had to leave out the <?php and ?> tags so my server wouldn't execute the code. sorry if i confused you.
use:
and to johny_d, sorry about that (long day,tired). i took your post personally and wasn't thinking at the time. my bad
use:
<?php
if (isset($_GET['show'])) {
$show = $_GET['show'];
if ($show == "disclaimer") {
include 'stuff.html';
}
}
else {
echo '<a href="show.php?show=disclaimer">click here to view disclaimer</a>';
}
?>and to johny_d, sorry about that (long day,tired). i took your post personally and wasn't thinking at the time. my bad
Last edited by kkeith29 : Sep 23rd, 2007 at 11:54 pm.
•
•
Join Date: Jan 2006
Posts: 28
Reputation:
Rep Power: 3
Solved Threads: 0
Working at it I commented out the echo lines and got rid of the href tag stuff. I went a little farther and added another copy of the script to have a second link and it works. But, can the two link scripts be combined somehow to just have one script covering all of it? I tried with an "else" command but couldn't get it to work.
Also, is there an elegant way (PHP?) to have a back link in place of the original link? Here's what I mean: I put an HTML href on the "disclaimer" content to go back to the show.php page, disguised as "close disclaimer". Instead, it would be real cool to have the original click here to view disclaimer change to click here to close disclaimer instead of the separate link. Am I getting too crazy or is it realistic?
Thanks again!
Also, is there an elegant way (PHP?) to have a back link in place of the original link? Here's what I mean: I put an HTML href on the "disclaimer" content to go back to the show.php page, disguised as "close disclaimer". Instead, it would be real cool to have the original click here to view disclaimer change to click here to close disclaimer instead of the separate link. Am I getting too crazy or is it realistic?
Thanks again!
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
is this what you are looking for?
http://www.banditssoftball.org/show.php
if so let me know and i'll post the code. otherwise tell me whats wrong and i'll fix it.
http://www.banditssoftball.org/show.php
if so let me know and i'll post the code. otherwise tell me whats wrong and i'll fix it.
Last edited by kkeith29 : Sep 24th, 2007 at 12:14 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Short guide to include RSS on your website (PHP)
- Safari does not print url on documents printed from web. (Mac Software)
- IE does not open *any* online web pages (Web Browsers)
- PHP Include ... Quote quirk (PHP)
- Can't Setup IE 6 SP1 (Web Browsers)
- CPanel/RVSkin/Fantastico Deluxe - Resellers Starting at $5 (Web Hosting Deals)
- Recomend a domain host (Web Hosting Deals)
- footer and nav include (HTML and CSS)
- Myriad of Graphic Cards (Monitors, Displays and Video Cards)
- Tutorials for Linux (*nix Software)
Other Threads in the PHP Forum
- Previous Thread: Validating an Image of Characters (COPA)
- Next Thread: Shopping Cart with an API?


Linear Mode