homepage Welcome to WebmasterWorld Guest from 54.237.95.6
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Adding links
ffoeg




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

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!

 

le_gber




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

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

ffoeg




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

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?

ffoeg




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

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.

omoutop




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

cookies, sessions or write to db - only way to maintain it (cant think of anything else) choose one and plan your page/code

ffoeg




msg:1253837
 11:31 am on Feb 20, 2006 (gmt 0)

What do you mean by writing to db? is that a Database?

topr8




msg:1253838
 11:38 am on Feb 20, 2006 (gmt 0)

>>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.

omoutop




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

topr8 u are correct, text file may be the solution to this problem :) i have forgotten it (dont use it too often myself)

ffoeg




msg:1253840
 1:20 pm on Feb 21, 2006 (gmt 0)

thanks. i'll search on google or something for that and start learning :)

BetterSEO




msg:1253841
 3:19 pm on Feb 21, 2006 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved