I have this basic question
Is this :
<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>
Different from this:
<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>
Or is there no difference?
(I am using CodeIgniter at present)
Unless I've missed something, the only difference (and there is at least one difference) is in the HTML, not in the PHP per se.
The second one has a link that starts with a /
, so that means it points to the link at
http://yoursite.tld/userconsole/etc
the first one points to /userconsole/etc
relative from the place you call it. So if you are in the dir /yourpath
, it will point you to http://yoursite.tld/yourpath/userconsole/etc
Lets say ur on www.somesite.com/url/
With
<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>
Ur Going to www.somesite.com/url/userconsole/indivstore/
With
<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">
<?php echo $obj->title; ?></a>
Here is the /
important! your going back to your root path that means www.somesite.com
. The result: www.somesite.com/userconsole/indivstore/
So at all its realative vs absolute path.
The first link has a relative path to the actual page you are visiting, but the second page has the absolute path so:
If you are at: http://example.com/something/other-thing
In first case the next url will be: http://example.com/something/other-thing/userconsole..etc
In the second case the next url will be: http://example.com/userconsole..etc
<a href="userconsole/indivstore/<?php echo $obj->store_id; ?>/">
is relative URL so if you are on http://host/site/current-page
it will point to http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?>
http://host/site/current-page/userconsole/indivstore/<?php echo $obj->store_id; ?>
which is wrong
<a href="/userconsole/indivstore/<?php echo $obj->store_id; ?>/">
is absolute URL so if you are on http://host/site/current-page
it will point to http://host/userconsole/indivstore/<?php echo $obj->store_id; ?>
http://host/userconsole/indivstore/<?php echo $obj->store_id; ?>
which is wrong if your site is under a sub folder.
the correct way to generate URL with codeigniter is using site_url() helper please check http://codeigniter.com/user_guide/helpers/url_helper.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.