Thread: Saving Variable

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0

    Saving Variable


    Hey everyone,

    I am going to do my best to explain what I need to do.

    Right, when someone (an affiliate) signs up on our site, I have it recreating our site under what ever username they give us. So if someone inputs the username 'bob', a folder is created and our site is replicated at www.domain.com/bob

    I have that working fine. My problem is I need to save that affiliate username in a php file in that affiliates folder. I need that variable somewhere to send through API's and such. Like when a customer signs up through that affiliate site, I need to send the affiliate username. So my question is, how do I save that variable in each affiliate site that is created? Is that possible? Manually adding it is kind of out the question, the company I work for is expecting thousands of people to sign up for this.

    Hope I explained it well. I appreciate any help. Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    194
    Rep Power
    77
    I just got sick from the thought of how your doing a basic register system

    Ever heard of MySQL?

    You could be doing this much easier if you used MySQL because all you would have to do is log the username into the MySQL database then retrieve it using something like index.php?user=bob and have a .htaccess that changes it to website/bob/ which really is index.php?user=bob

    see how much easier that would be? And if there really will be thousands of users like the company expects and the website gets replicated each time then that will be one giant disk usage and bandwidth usage for that website which would probably cause the hosting company to take it down

    Anyways about your question, just have php read from a users.txt file and insert the username in their then when that username is needed again have php read that file and pick out the required name as in the file stores all of the username and not a seperate file for each user
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    unless your affiliates are supposed to change your whole code, physically duplicating it is a bad idea in the first place.

    I guess you'll rather want a single code base with custom templates or extensions for the affiliates. Then you'd simply have a single application that serves the content dynamically depending on the URL.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by dkeeper09
    I have that working fine. My problem is I need to save that affiliate username in a php file in that affiliates folder. I need that variable somewhere to send through API's and such. Like when a customer signs up through that affiliate site, I need to send the affiliate username. So my question is, how do I save that variable in each affiliate site that is created? Is that possible? Manually adding it is kind of out the question, the company I work for is expecting thousands of people to sign up for this.
    An easier solution might be to create a separate configuration file dynamically whenever you clone the site software. This can be a PHP file declaring just that variable, or an .ini file your PHP takes in. Just note that if it's .ini, .xml, etc., that you'll want to prevent the world from being able to view it directly; an .htaccess block or similar could help there.

    Alternatively, if the directory is always going to be the username you could have your software look at the directory it resides in and use that information to glean the username.

    But as the others have said, based on the available information this sounds like a peculiar approach--especially if all the clones remain near-identical.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0
    Originally Posted by jack13580
    I just got sick from the thought of how your doing a basic register system

    Ever heard of MySQL?

    You could be doing this much easier if you used MySQL because all you would have to do is log the username into the MySQL database then retrieve it using something like index.php?user=bob and have a .htaccess that changes it to website/bob/ which really is index.php?user=bob

    see how much easier that would be? And if there really will be thousands of users like the company expects and the website gets replicated each time then that will be one giant disk usage and bandwidth usage for that website which would probably cause the hosting company to take it down

    Anyways about your question, just have php read from a users.txt file and insert the username in their then when that username is needed again have php read that file and pick out the required name as in the file stores all of the username and not a seperate file for each user
    Hey jack, I'm pretty new to all this. I do like your suggestion though. Can you point me in the right direction or give me an example of some code that could do your idea with the MYSQL.

    Thanks for the help.
  10. #6
  11. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    The way I'm interpreting your situation seems to be a bit different than jack's. It's not a "basic register system". It's a system in which end users will access an instance of a website that belongs to a specific affiliate.

    If that assessment is correct, then it'll help us advise you to understand the situation more fully.

    I've gathered so far that an affiliate signs up, gets their own copy of the site, then....

    Do they give out the "www.domain.com/bob" to people?
    Will that URL format be consistent for all affiliates?
    Might different affiliate's copies ever change, in form or function?
    Last edited by dmittner; June 26th, 2013 at 03:11 PM.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0
    Do they give out the "www.domain.com/bob" to people?
    Yes, so when an affiliate wants a customer to sign up, the customer can go to that affiliates url and sign up. The customer information is being sent to authorize.net and our crm system, so I need a way to track what affiliate that customer came from.

    Will that URL format be consistent for all affiliates?
    Yes, the affiliate will provide their username. That username variable will be the name of the folder that is created. Always.

    Might different affiliate's copies ever change, in form or function?
    No, they won't ever change. Under the rare circumstances one needs changing, I can do that manually.


    Hope that helps explains the situation a bit dmittner.
  14. #8
  15. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by dkeeper09
    Hope that helps explains the situation a bit dmittner.
    Yep.
    I feel more comfortable now pointing to a part of what jack suggested earlier:

    ... have a .htaccess that changes it to website/bob/ which really is index.php?user=bob
    In other words, leveraging a URL Rewrite, the world will see "domain.com/bob" but your application will act as though they entered "domain.com/index.php?affiliate=bob".

    Once your main index.php file knows the affiliate from that passed variable, the subsequent signup can be made on their behalf, and you only need one instance of your application.

    I don't have access to my server to pull an example from my own site, but it should be something like this:

    .htaccess
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\/]+)$ index.php?affiliate=$1 [L]
    It'll require Apache's mod_rewrite, which you may or may not have enabled already...

    Comments on this post

    • Jacques1 agrees
  16. #9
  17. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Even if your affiliates had the ability to customize parts of the application, you still wouldn't clone the whole thing. You'd offer an extension mechanism or something like that.

    Did you seriously consider to run thousands(!) of copies of the same application on your server? How did you plan to maintain them all? I mean, every change in the application would have to be done on every single copy. Not to mention the gigantic waste of resources.

    I don't wanna put you down, but maybe this project is a bit too much for you to handle. If you barely know how to write a dynamic website, how are you gonna create a complex infrastructure for thousands of affiliates? That'll take more than "SELECT * FROM affiliates" and a bit of URL rewriting.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0
    Man, sounds like I made some people a little angry with my approach.

    Maybe I am a bit out of my league, but the company wants something working now and if we really expand to as many affiliates as they think, we can bring in someone to do this the right way.

    I know all affiliate sites will be the same and there will be no changes that would need to be made. I didn't know there was a better way to do this besides copying the site, so it seems this URL rewrite is my next best option.

    But back to your post dmittner,
    When an affiliate signs up, do I need to send that username to the database and return that value or how does that work?

    Sorry for all the questions. I really do appreciate the help.
  20. #11
  21. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by dkeeper09
    Maybe I am a bit out of my league, but the company wants something working now and if we really expand to as many affiliates as they think, we can bring in someone to do this the right way.
    Grabbing a contractor might be viable as well. I've been contemplating offering my services. I'm already doing contracting work for my previous employer so doing a bit more wouldn't be unprecedented...

    (I can picture Jacques' head exploding right now...)

    Don't get us wrong; we all appreciate people wanting and willing to learn to use PHP properly. But I know I'm sometimes amazed what companies are asking new PHP developers to do. That's not a slight against new developers in any way, but some concepts take years to understand and appreciate the importance of--especially in terms of security, privacy, and best practices; things a company should be very attentive to.

    10 years with PHP and I'm still learning them.

    But back to your post dmittner,
    When an affiliate signs up, do I need to send that username to the database and return that value or how does that work?

    Sorry for all the questions. I really do appreciate the help.
    Strictly speaking, based on the information provided, you don't need to do anything. Anyone could arbitrarily give out a "domain.com/something" URL and your system can pass that "something" through when users sign up.

    But chances are that lack of control is just going to result in a lot of garbage data that hurts both the affiliates and your company.

    So you'll want some validation around it; you'll want to verify that the affiliate name they provide is a legitimate affiliate, or otherwise send an error message of some sort.

    How you perform that validation can vary, possibly based on the amount of data you're collecting during the affiliate signup process.

    The recommended approach would be to store this information in a MySQL database and reference that database when a user comes to sign up; just check that the affiliate name they provide in the URL is one you recognize. This'll help control the process and keep the resulting sign-up data clean.

    If you don't use a database already and you're only dealing with the affiliates "name", then you could also store the names in a file and your application could check against that. But we'd all advise against this; using a database is generally cleaner--one of those best practices things.

    Does that all make sense?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0
    I definitely understand where you are coming from. I know you guys are providing help and advice, not your entire evening writing php code for free.

    I understood all of that. I currently have some of the affiliate information we take being sent to a mysql database already, so that is taken care of. I wont need to write it to a file.

IMN logo majestic logo threadwatch logo seochat tools logo