mosey Posted August 28, 2007 Share Posted August 28, 2007 This is a continuation (sort of) from my previous post, but I would really appreciate some help with this! I currently have a PHP file that already includes variables such as 'username' and 'password' (for authentication), but I would like to collect the form data submitted, concatenate everything into one string, and then open up this string (which is essentially a url) I undrstand (with thanks to schme16) that I have to use $_POST['name_of_form input'] to retrieve the data, but after that I would like to put all of these into one string that looks like http://www.wbsite.com/something.php?username=$username&password=$password&msg=$message and then use fopen to load this url. Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/ Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 <?php $username = $_POST['username']; $password = $_POST['password']; $message = $_POST['message']; $url = "http://www.wbsite.com/something.php?username=$username&password=$password&msg=$message"; $file = fopen($url); ?> Give that a shot =] Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-335891 Share on other sites More sharing options...
mosey Posted August 28, 2007 Author Share Posted August 28, 2007 Thank you very much! This worked for me (but I had to add an extra value to the fopen part:) $file = fopen($url,'r'); to indicate 'read only' or something like that. Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-336010 Share on other sites More sharing options...
ReDucTor Posted August 28, 2007 Share Posted August 28, 2007 It would be easier to use file_get_contents() and also you should do urlencode() on those paramaters that your passing to the url. Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-336012 Share on other sites More sharing options...
mosey Posted August 28, 2007 Author Share Posted August 28, 2007 ReDucTor: Thanks for the suggestion I've just tried to read up abit on get_file_contents and have understood it is for PHP5 (which isn't a problem) But I was wondering how I would apply it here (as a PHP newbie)? Would it literally be replacing the $file part ith get_file_contents($url) And for the encode part, is it something like $username = urlencode($_POST['username'])' or can I use this function later? I guess it would be easiest if I could encode all the parameters in one go or something. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-336043 Share on other sites More sharing options...
ReDucTor Posted August 28, 2007 Share Posted August 28, 2007 Well little syntax error there $username = urlencode($_POST['username']); Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-336054 Share on other sites More sharing options...
mosey Posted August 28, 2007 Author Share Posted August 28, 2007 Ah, soz, my bad there Thanks for the correction! I guess it's not possible to universally encode everything but as there aren't too many variables, this is fine! Quote Link to comment https://forums.phpfreaks.com/topic/66977-solved-collect-form-data-use-variables-concatenate-into-string-and-fopen-string/#findComment-336174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.