0

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)

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

<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; ?> 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; ?> 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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.