I know how plain links work, but I've never really got any good info on how they work so they can be placed without a whole lot of trouble when re-editing code.
There's the different links.
http://www.mydomain....ctory/index.php
directory/index.php
/directory/index.php
$_SERVER['PHP_SELF']
Then there are also these globals:
'SCRIPT_NAME'
'REQUEST_URI'
'PATH_INFO'
When are these globals good to use.
Say for instance I have some links in a script and I move the script into an include. If the links are formatted like /directory/index.html the links will suddenly not work.
Links in PHP 'how do they work?'
Page 1 of 14 Replies - 263 Views - Last Post: 21 January 2012 - 09:23 PM
Topic Sponsor:
Replies To: Links in PHP 'how do they work?'
#2
Re: Links in PHP 'how do they work?'
Posted 21 January 2012 - 08:55 PM
Avoid using the $_SERVER superglobal here, as you are opening yourself up to cross-site scripting attacks. You can set up your directory structures to use relative links. If you want to access a child directory, use /child. To access a file in the parent directory, you can do ../file_in_parent.
#3
Re: Links in PHP 'how do they work?'
Posted 21 January 2012 - 09:13 PM
Quote
Links in PHP 'how do they work?'
They don't. PHP doesn't do anything with links because to PHP links are just text, like all HTML. You can use PHP to build a link and then send it to the browser. When a link you've built doesn't work look at the browser's source code to see if you built it correctly.
#4
Re: Links in PHP 'how do they work?'
Posted 21 January 2012 - 09:18 PM
macosxnerd101, on 21 January 2012 - 09:55 PM, said:
Avoid using the $_SERVER superglobal here, as you are opening yourself up to cross-site scripting attacks.
That's good to know.
CTphpnwb, on 21 January 2012 - 10:13 PM, said:
Quote
Links in PHP 'how do they work?'
They don't. PHP doesn't do anything with links because to PHP links are just text, like all HTML. You can use PHP to build a link and then send it to the browser. When a link you've built doesn't work look at the browser's source code to see if you built it correctly.
I was hoping to figure out a way to use links so they can be portable between installations, and can be moved to an include without breaking.
Should I really just read the code and change them when they are moved?
This post has been edited by hiddenghost: 21 January 2012 - 09:18 PM
#5
Re: Links in PHP 'how do they work?'
Posted 21 January 2012 - 09:23 PM
Quote
I was hoping to figure out a way to use links so they can be portable between installations, and can be moved to an include without breaking.
You should use relative links, which doesn't involve any PHP- it's all HTML. If you are familiar with Unix directory structuring, set your directory structure up to take advantage of that.
This isn't a PHP question really, so I'm going to move this to Web Development for better discussion.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|