Absolute URL creation with PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
christinemarie
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 5:31 pm

Absolute URL creation with PHP

Post by christinemarie »

Hello,

I've never used PHP before, and was advised that it was the best method for creating an absolute URL in the situation described below.

My navigation is in one div, while all other pages for the site are loaded via ajax into a div below it. If the base url is http://www.mysite.com/index.html, for example. When a visitor clicks Page Two, and pagetwo.html loads into the div below, the address bar still says http://www.mysite.com/index.html. I would like for it to change to http://www.mysite.com/pagetwo.html.

Can anyone advise me on how this can be done, keeping in mind that I am a full-fledged beginner to PHP. I can provide links/code if necessary.

Thanks in advance,
Christine
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Absolute URL creation with PHP

Post by requinix »

Don't use AJAX - just use normal links like everybody else does.

Code: Select all

<a href="/pagetwo.html">Page 2</a>
Which has a corollary:
You can't change what you see in the address bar without browsing to another page.
christinemarie
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 5:31 pm

Re: Absolute URL creation with PHP

Post by christinemarie »

I have to use ajax if I want my page to open in a specific div. Otherwise an iFrame. But I am going to try looking into Dreamweaver to see if there's a function built-in for doing this.
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: Absolute URL creation with PHP

Post by Reviresco »

You have to reload the page. The whole purpose of Ajax is to allow loading of content without reloading the page -- so you have to choose one or the other.
christinemarie
Forum Newbie
Posts: 3
Joined: Wed Mar 04, 2009 5:31 pm

Re: Absolute URL creation with PHP

Post by christinemarie »

A programmer friend of mine suggested the following, which is why I posted here initially:

Make your new page page.php (instead of page.html) and put some scripting in it to tell if it is being accessed directly or via AJAX. If via AJAX, just return what is currently there. If it is directly, then wrap the current content with the header and footer. You could probably do the same thing with javascript.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Absolute URL creation with PHP

Post by papa »

Ajax is javascript. :)
Post Reply