-1

The question speaks for itself.

Ideally I'd like to feed the program with a list of links and have it redirect to the next URL in the chain once it has been clicked.

In this scenario the next visitor will not be able to access the previous link but will be met with a fresh result.

I also would like each visitor to only be able to access the link they are directed to and not have access to any URL in the chain before or after.

Is this possible and if so how can this result be achieved?

All ideas welcome.

ShpatG
  • 1
  • We need some code in order to see what's going on. – Jorel Amthor Mar 26 '21 at 14:58
  • This needs to be done on the server. For each user it should remember (in a DB or session data) which page the user last visited, and then redirect them to the next one in the sequence. – Barmar Mar 26 '21 at 15:03
  • Thanks for the reply Jorel. So far I have not coded anything but if you have any ideas on how to build this I'd be interested to hear. – ShpatG Mar 26 '21 at 15:04
  • Hi Barmar maybe I didn't make it clear in the post. I dont want each vistor to have access to the other links. Only to the link they are redirected to. I want the next visitor to be redirected to the next link and so on. Every visitor will receive a unique link and not any other link at all. – ShpatG Mar 26 '21 at 15:06

1 Answers1

0

Sure. You can use a Flask app for this.

Create a Flask app and add a route of the initial link all visitors will have.

from flask import Flask, redirect
app = Flask(__name__)

@app.route('/my-redirecting-link')
def hello_world():
    next_url = "http://www.example.com"
    return redirect(next_url, code=302)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

And now improve the code above such that next_url is chosen dynamically. I would use SQLAlchemy and have a table with (url, used). Then you retrieve the first non-used link and redirect to it.

As for one user only being able to access 1 page (and not keep getting new pages), I would use a JWT or UUID4. What I would do is create a custom link for each person, and have the link include the token/password (this way the user does not even realise that is introducing a password). When the person clicks the link, you check which is the next unused redirect, redirect him, and mark the token as used. Then the user can either use the new link, or you can store a relation between tokens and which redirect link have they been assigned. This will work well; if you expect a lot of users and links (a large scale thing), then it would be interesting to consider methods which don't involve storing the relations to a db.

As for the IP, I would not choose that option (most of people have dynamic IPs, which change).

miquelvir
  • 1,748
  • 1
  • 7
  • 21
  • That sounds like a great solution. How do I link the table to the code in Flask and what format should it be created in? Appreciate your speedy response. If I provided you with a list of links could you share with me a flask application that I could use? I'm not a coder myself! – ShpatG Mar 26 '21 at 15:16
  • Also does this contain a blocking feature to prevent each visitor from being able to access a new link? I assume not. I only want them to receive one link and have unlimited access to it but not be able to visit any other link in the chain. – ShpatG Mar 26 '21 at 15:29
  • SO is not a coding service, if you are not here to learn how to code I suggest you head out to Fiverr or similar places, where coders like me will be happy to code it for you. My answer was the basic idea; it does not implement blocking. How do you decide if a user is the same? Same IP? Or do you want them to log in? – miquelvir Mar 26 '21 at 15:33
  • perhaps a passcode could be inputted that would only allow them to access the first link that they access and no other link in the chain? Just brainstorming ideas. What would you do? Tracking their IP would be a more frictionless solution. Would this require much more complexity in the code or is there an existing resource that I could import. I am interested in trying to build it myself as a challenge! – ShpatG Mar 26 '21 at 15:58
  • Thats great! If you have further questions, I suggest the Flask subreddit. I will now update the answer. – miquelvir Mar 26 '21 at 16:02