Jump to content

Recommended Posts

Posted

Hey,

 

I'm not too good with html, and I'm not sure if this needs to go here or in the scripting forum but seeing as this is the web developer forum I thought I'd post it here. So basically I want to know if its possible to make a link change its URL once its been clicked. So person 1 would click it and get sent to google, person 2 comes along and clicks the same link and they get sent to msn, person 3 comes along and it sends them to a different website. I've had a quick look online and have seen people talking about doing it through javascript, but I was wondering if there was a way to do it through HTML or PHP at a push.

 

Thanks for any help/advice.

Posted
How would it define which user is which? I don't know the answer to your question but i'm interested if this is possible and how it works.
Posted (edited)
Hey,

 

I'm not too good with html, and I'm not sure if this needs to go here or in the scripting forum but seeing as this is the web developer forum I thought I'd post it here. So basically I want to know if its possible to make a link change its URL once its been clicked. So person 1 would click it and get sent to google, person 2 comes along and clicks the same link and they get sent to msn, person 3 comes along and it sends them to a different website. I've had a quick look online and have seen people talking about doing it through javascript, but I was wondering if there was a way to do it through HTML or PHP at a push.

 

Thanks for any help/advice.

 

If you want each link to constantly be the same for each user (User A always gets Site 1, user B always gets Site 2 etc), you're going to need some kind of challenge-and-authentication mechanic to determine who they are first, and then I'd suggest you'd be right in thinking you can use PHP to make it happen.

If you want a link to rotate between fixed urls each time the page is loaded independent of who loads the page, that's probably possible with just PHP on its own.

 

Sounds like you're over-complicating things, though. What is it that makes something like a bookmark/favourite/shortcut unacceptable to these users?

Edited by Garacesh
Posted
okay maybe i should have tried to be a bit clearer. random person 1 go to website and clicks link and gets sent to google, random person 2 goes to website and clicks link and gets sent to msn. it doesnt have to be person1 always get sent to the same website. If person 1 went to the website and clicked the link multiple times they would be sent to the different websites.
Posted
okay maybe i should have tried to be a bit clearer. random person 1 go to website and clicks link and gets sent to google, random person 2 goes to website and clicks link and gets sent to msn. it doesnt have to be person1 always get sent to the same website. If person 1 went to the website and clicked the link multiple times they would be sent to the different websites.

 

Then yes it's possible.

 

I'm not very good with it personally (I'm more of a CSS guy, I never really put in the time to learn PHP..), but yes, that's definitely possible with PHP.

In fact, it's the very way a lot of static ads on websites are generated. Probably worth starting your search there, see if you can find some random-ad scripts and adapt them.

Posted (edited)

You could make sure users are consistently sent to the same random website with the use of a cookie - I know its not needed now but it would be rather simple to just record URL or something to a cookie and read that back. An Auth method could be complete overkill. This being said - I realise this aspect isn't needed now.

 

PHP could be overkill too, easily doable with PHP but using AJAX to load URLs from file then pick one at random and push user forwards to that address could be easier?

 

OR just load an array with items in code and return a random item, pure JS?

Edited by ThomL
  • Thanks 1
Posted (edited)

Basic idea: Have a static HTML page that points to another page, such as url/subdir/HREFrotator.php, which has a PHP script to rotate the redirect.

 

The HTML to redirect is:

(Where ## is after how many seconds)

 

So if you make the PHP script generate a different line of code each time, you're golden. It just has to pick from




  • Etcetera

Then it serves that line of code as its own HTML page (possibly with some

thrown in for good measure) and redirects them to where you want them to go.

 

This solves your issue of 'every time the link is clicked' because it then you don't have to worry about the what if the page is loaded, it moves to the next url, but then the link isn't clicked, since the script is only called when the link is clicked.

Does that make sense?

Edited by Garacesh
Posted

Frugal, that looks like what i was after at first glance, but alas its not. I think thoml and garacesh are hitting the nail on the head, and i'll have to give garacesh's recommendation a go. Would I just be able to put

 

 

in a html file, and then do the

 

 




in a separate html file and it will work? Like how do I chose what text would be displayed? like would that produce the word refresh that goes to the redirect php when clicked?

Posted
Frugal, that looks like what i was after at first glance, but alas its not. I think thoml and garacesh are hitting the nail on the head, and i'll have to give garacesh's recommendation a go. Would I just be able to put

 

 

in a html file, and then do the

 

 




in a separate html file and it will work? Like how do I chose what text would be displayed? like would that produce the word refresh that goes to the redirect php when clicked?

 

Nonono.

 

From my (very limited) knowledge of PHP, it works like this:

 

You set up a webserver server to use PHP.

You make a page with a link (Click me!)

When a user clicks it, their web browser loads the PHP script.

The PHP script does as its told, and generates a the next link in the sequence (how you do that, I don't know, but I know it's possible)

The PHP script then presents its finished HTML to the browser and the browser loads it like a normal web page.

This page would, if you viewed its source, just say , because that's how PHP works. They wouldn't see the script, they only see the result of the script.

Posted

Slap this in a .html - much easier than setting up and learning PHP:






This returns a random URL from a variable with Javascript:
>Click Me!



<br />
<br />
function getURL() {<br />
<br />
var items = Array('www.googel.com','www.youtube.com','www.bing.com','www.bbc.co.uk','www.edugeek.net');<br />
var item = items[Math.floor(Math.random()*items.length)];<br />
<br />
document.getElementById("demo").innerHTML = item<br />
}<br />
<br />




 

Although this is just returning from a variable it shouldn't take much to initiate a redirect.

  • Thanks 1
Posted
That is freaking awesome :o and it literally what i wanted, how would I get it to actually open a new tab instead of display the url underneath the button?
Posted

This might work, i don't have a webserver handy to test with...

 






This redirects a random URL from a variable with Javascript:
>Click Me!

<br />
function getURL() {<br />
var items = Array('www.google.com','www.youtube.com','www.bing.com','www.bbc.co.uk','www.edugeek.net');<br />
var item = items[Math.floor(Math.random()*items.length)];<br />
var win = window.open(item, '_blank');<br />
win.focus();<br />
}<br />





  • Thanks 1
Posted
Ah, but isn't that a random url, not sequential rotation?

 

 

Currently it is random - I missed the part where we needed it to be sequential :/

Posted
random is better for what i want XD I just thought it might get abit hard to follow

Ah that's OK then @Knil92 - then I was making it way more complicated than needed to be on the assumption it needed to be sequential rotation. As a rule, random's always easier, 'cause it doesn't need to track where you're at currently.

Posted
That's awesome, it opens it in a new tab but with the file location of the html file, so it looks like file:///D:/Website%20test/www.bing.com rather than it going to Bing but its given me something to play with so thank you :D
Posted
That's awesome, it opens it in a new tab but with the file location of the html file, so it looks like file:///D:/Website%20test/www.bing.com rather than it going to Bing but its given me something to play with so thank you :D

 

You'd need to alter one line to this:

 

[color=#333333]var win = window.open('http://' + item, '_blank');[/color]

 

to get it to go to the website rather than /www.bing.com

Posted
Ah that's OK then @Knil92 - then I was making it way more complicated than needed to be on the assumption it needed to be sequential rotation. As a rule, random's always easier, 'cause it doesn't need to track where you're at currently.

If its really needed we can track with cookie to enable this.

Posted (edited)

No. Not unless you use ./ urls.

 

If you specify http://url that's where it goes to. It only does relative links if you use ./ (or other such relative paths like ../ etc)

 

Sorry, I misunderstood the scripts current behaviour. Katy's response should sort you out.

Edited by Garacesh
  • Thanks 1
Posted
I mean it would be cool if you could track what links the user has been sent to previously so they don't get sent to those links unless they have been sent to all of them and then it resets

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...