User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2006
Posts: 28
Reputation: Syakoban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Syakoban Syakoban is offline Offline
Light Poster

Help Using include in a URL???

  #1  
Sep 22nd, 2007
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:
<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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Using include in a URL???

  #2  
Sep 23rd, 2007
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.
Last edited by kkeith29 : Sep 23rd, 2007 at 6:38 am.
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Using include in a URL???

  #3  
Sep 23rd, 2007
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.
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Using include in a URL???

  #4  
Sep 23rd, 2007
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.
Reply With Quote  
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation: johny_d is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
johny_d's Avatar
johny_d johny_d is offline Offline
Junior Poster in Training

Re: Using include in a URL???

  #5  
Sep 23rd, 2007
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?
Reply With Quote  
Join Date: Jan 2006
Posts: 28
Reputation: Syakoban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Syakoban Syakoban is offline Offline
Light Poster

Re: Using include in a URL???

  #6  
Sep 23rd, 2007
Originally Posted by kkeith29 View Post
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
Reply With Quote  
Join Date: Jan 2006
Posts: 28
Reputation: Syakoban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Syakoban Syakoban is offline Offline
Light Poster

Re: Using include in a URL???

  #7  
Sep 23rd, 2007
OK I tried the <?PHP ?> tags around the code and it works on my server now. I'm guessing some servers are stricter than others???

Also how do I get the

echo '< ' . 'a href="show.php?show=disclaimer">click here to view disclaimer<' . '/a>';

to appear as just: click here to view disclaimer

Thanks.
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Using include in a URL???

  #8  
Sep 24th, 2007
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.
Last edited by kkeith29 : Sep 24th, 2007 at 12:14 am.
Reply With Quote  
Join Date: Jan 2006
Posts: 28
Reputation: Syakoban is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
Syakoban Syakoban is offline Offline
Light Poster

Re: Using include in a URL???

  #9  
Sep 24th, 2007
Almost...

Instead of the links moving around I was hoping that the original link would change to close disclaimer in the same location. That way the disclaimer can load below the link and not affect the layout of it like:

BEFORE

header
view warning
view disclaimer
footer

AFTER

header
view warning
close disclaimer
blah blah blah blah blah blah blah blah blah blah blah blah
footer

OR

header
close warning
blah blah blah blah blah blah blah blah blah blah blah blah
view disclaimer
footer

It kinda evolved after seeing your example in action... I tried to play with your code but I don't have the skills.

Thanks again, I appreciate the help!
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation: kkeith29 is on a distinguished road 
Rep Power: 3
Solved Threads: 72
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Practically a Master Poster

Re: Using include in a URL???

  #10  
Sep 24th, 2007
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC