Welcome to WebmasterWorld Guest from 54.162.240.235

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Adding links

     
11:10 am on Feb 19, 2006 (gmt 0)

5+ Year Member



I am really new to PHP (Only been doing it for the past two weeks :) and I need a bit of help.

What I basically want to do is to have a text box in a form, with a "submit" button next to it.

What will happen is that the user will type in a URL in the textbox, and press submit. That form then writes that URL to the original page, providing a link to the given URL.

The problem that I can foresee is that when the user refreshes the page, that link that was uploaded would disappear. But I don't want this to happen.

I hope I made myself clear, and I would really appreciate it if anybody could help!

11:20 am on Feb 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you could try writing the url to a cookie or a session variable and then fetching the info using php - have a look on google for 'php sessions' or 'php cookies'

the session would last as long as the visitor has his browser window open
the cookie would last as long as you set it to last

hope this helps

11:33 am on Feb 19, 2006 (gmt 0)

5+ Year Member



I was actually considering using cookies.

But is there no way to write the link into the actual html of the original page when the user clicks the button?

10:27 am on Feb 20, 2006 (gmt 0)

5+ Year Member



Can anyone else help...please?

I realised that considering forums can do it, there must be a simpler way to do it. Based on the forum scripts.

11:14 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cookies, sessions or write to db - only way to maintain it (cant think of anything else) choose one and plan your page/code
11:31 am on Feb 20, 2006 (gmt 0)

5+ Year Member



What do you mean by writing to db? is that a Database?
11:38 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



>>But is there no way to write the link into the actual html of the original page when the user clicks the button?

yes of course there is.

search for something like: editing text file php

basically your html page is the text file, submit the form to a php page that gets the form value, opens the text file, adds the url to the text file, closes the text file and finally redirects the user to the html page.

much simpler than it looks once you start.

11:49 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



topr8 u are correct, text file may be the solution to this problem :) i have forgotten it (dont use it too often myself)
1:20 pm on Feb 21, 2006 (gmt 0)

5+ Year Member



thanks. i'll search on google or something for that and start learning :)
3:19 pm on Feb 21, 2006 (gmt 0)

10+ Year Member



Why not use GET to append the URL as a variable onto the end of the original URL like:

<?php echo "<a href=\"$url\">$url</a>";?>
<form action="" method="get">
<input type="text" name="url"> <input type="submit" value="Submit">
</form>

Now when the page is refreshed, the variable remains on the end of the original URL like: mydomain.com/index.php?url=example.com

 

Featured Threads

Hot Threads This Week

Hot Threads This Month