About Club osCommerce

Showcasing osCommerce - the good, the bad and the ugly!

StumbleUpon It! DIGG It!

Cookies, Links, Session IDs

Written By Gary on Oct 06 2008 ·

Cheri asks;

I have an extra text box on my index page and I would like to add hyperlinks. I'm told that the HTML may cause problems, including the possibility of my customer's carts getting emptied and/or logging the customer out. Do you agree with this? And what issues would forcing cookies possibly cause? Please explain in as simple terms as possible, I don't know code, etc. The store is doing pretty well right now and the last thing I want to do is chase away customers. I just think adding hyperlinks on the front page would make the spiders happy. And we like happy spiders :-)

All you need to remember is that any links that go to other osCommerce based pages in your own site MUST carry a SID. Any links elsewhere, need not.

So, to carry a SID, use the "tep_href_link" function;

PHP:
  1. <a href="<?php echo tep_href_link(FILENAME_SHIPPING); ?>">Shipping</a>

as an example. Note that in the example I have simplified a bit asyou would want to use the language definitions rather than just type "Shipping". But anyway, use the tep_href_link to other osCommerce pages and all will be well.

The tep_href_link function also accepts parameters - so if you wanted to link to a category you could do this:

PHP:
  1. <a href="<?php echo tep_href_link(FILENAME_DEFAULT, 'cPath=24'); ?>">Widgets</a>

Obviously in the example above we are linking to category ID = 24. You can pass more parameters as you need them;

PHP:
  1. <a href="<?php echo tep_href_link(FILENAME_REDIRECT, 'action=manufacturer&manufacturers_id=3'); ?>">Manufacturer Name</a>

In this one, we are linking the manufacturers ID and setting an action. The action is carried out as per the codebase in the the file we link too - in this case "FILENAME_REDIRECT" (aka redirect.php).

You can also tell the tep_href_link to link via SSL - which you should do when linking to any page that requires the user to be logged in. Example:

PHP:
  1. <a href="<?php echo tep_href_link(FILENAME_LOGIN, '', 'SSL'>Login</a>

What this will do is link the SSL page iny our site (https://) rather than the normal http page. Assuming you have SSL set up of course!

Hope this helps.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive. Cheers!


No Comments

No comments yet.

Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!