SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict CasualNerd's Avatar
    Join Date
    Feb 2005
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing / exchanging URLs without a database ?

    I just wrote a simple redirect script so that I could send traffic off-site using the format: domain.com/redirect.php?url=redirecting.com

    Initially I just used a switch statement with half a dozen URLs where the '.com' url would be changed for the full url, like 'http://www.redirecting.com/folder/affiliateid' so I'm just simplifying URLs for the sake of keeping things easy while I build pages.

    This all works fine but it's quite useful and I'd like to add a heap more links. I'd keep using the same format but I would imagine there's a more efficient way than using a switch ? What's the best way to do it without involving a database (mysql etc) ? I believe I could use a flat file database but I wouldn't know where to start.
    Looking for people to post on an Adult forum.
    Must be cheap or willing to trade posts.

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make an array like 'url1' => 'redirect1', 'url2' => 'redirect2' etc and pull the addresses out of it: if(isset $array[$param]) redirect($array[$param])

  3. #3
    SitePoint Addict CasualNerd's Avatar
    Join Date
    Feb 2005
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I haven't used arrays, so are they the most efficient way of doing this ?

    I want to be able to add maybe a few hundred links and not have anything slow down.
    Looking for people to post on an Adult forum.
    Must be cheap or willing to trade posts.

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2007
    Location
    In the blogosphere
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In that case you really should be using a database But like frog said, you could store a serialized array and open and write the file as needed. It would probably work a few hundred links but will not for a few thousand as it'd load of all the links in an array.
    bLueFrogX's Blog - Random Ramblings of a NEET Techie ★

  5. #5
    SitePoint Addict CasualNerd's Avatar
    Join Date
    Feb 2005
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bluefrogx View Post
    In that case you really should be using a database But like frog said, you could store a serialized array and open and write the file as needed. It would probably work a few hundred links but will not for a few thousand as it'd load of all the links in an array.
    So is a flat file database possible / suitable ?

    If it's not that simple I'll just forget about it, it wouldn't be worth the hassle.
    Looking for people to post on an Adult forum.
    Must be cheap or willing to trade posts.

  6. #6
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A flat file database is possible, but as bluefrogx recommended, you'd be much better off using a real database. If I may ask, why are you hesitant to use one? It's really not all that complicated.

  7. #7
    SitePoint Addict CasualNerd's Avatar
    Join Date
    Feb 2005
    Posts
    206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allspiritseve View Post
    A flat file database is possible, but as bluefrogx recommended, you'd be much better off using a real database. If I may ask, why are you hesitant to use one? It's really not all that complicated.
    This script is more to mask affiliate links so if they change their links I only change it in one place, not dozens of places on dozens of pages. It would also be nice to throw it up on a few different domains.

    If I'm going to go for a database there's tons of ad rotation style programs out there I could use.
    Looking for people to post on an Adult forum.
    Must be cheap or willing to trade posts.

  8. #8
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then why don't you? If your switch is becoming unwieldy, it might be time to switch to a database solution anyways, whether you write it yourself or not.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •