1

I am creating a cms where an user can upload an url with title. These URLs and titles, I am accessing dynamically in my front page of the website. Suppose if I uploaded an url : www.google.com and title : google; then my front page displays the url : http://localhost/project/index.php/www.google.com and title : google

This is the foreach loop which I am running in my view page to display the url and title.

 <?php foreach($links as $a) { ?>
        <a href="<?php echo $a -> url; ?>" class="quicklinks"><b><?php echo $a -> url_title; ?></b></a>
 <?php } ?>

where echo $a -> url; is pointing to the URL column in the table and echo $a -> url_title; is pointing to the url title column of the table. I am using datampper for the DB Coding. Please help me to display only www.google.com . Thank you so much in advance.

3
  • 1. have you confirmed that the correct 'www.google.com' is being stored in the database? 2. have you checked with firebug/chrome console what is actually being rendered on the page there? Commented Jun 21, 2012 at 17:26
  • Hi, Thanks for the quick response. Yes , it is storing perfectly in my database as www.google.com and when I am checking it with firebug it displays same as www.google.com but when I click on the link to open it goes to localhost/project/index.php/www.google.com . Please help me to find out the possible error. Thanks. Commented Jun 21, 2012 at 17:36
  • when I view the source of the page it displays following <a href="www.rediff.com.html" class="quicklinks">rediff</a> Commented Jun 21, 2012 at 17:43

1 Answer 1

1

Just add 'http://' in front of stored URL (if it doesn't contain this) or ammend your script to add 'http://' (or 'https://') to a submited link before inserting it into database.

For this you may utilize CodeIgniter's prep_url() function from URL helper:

http://codeigniter.com/user_guide/helpers/url_helper.html

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

1 Comment

Thanks Aidas. Its working now. I need to change my code in my cms for valid url so that an admin can insert only valid url starting from http or https. You saved my time. Thank you soooooo much once again. :)

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.