Hodo Posted June 28, 2007 Share Posted June 28, 2007 When you open a browser and type in a url as in www.myplace.com I have seen url addresses with what appears to be a command. I.E. www.myplace.com/myfile.php?=4 I want to know if the ?=4 at the end is the same as a POST command to the php file or can this method be used to send a command to php using the url as input? Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/ Share on other sites More sharing options...
r-it Posted June 28, 2007 Share Posted June 28, 2007 i think you're trying to use the $_GET method, it's sort of something like this: www.myplace.com/myfile.php?size=4 and getting the value in php you would use this: $size = $_GET['size'];, i don't quite understand what you would get with that 4 thing Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/#findComment-284783 Share on other sites More sharing options...
sKunKbad Posted June 28, 2007 Share Posted June 28, 2007 Play with the code below on your server, making two pages, a form page and a script to process the form. Name the script that processes the form "formprocesser.php". Simple Form on Page #1: <form action='formprocesser.php' method='get'> <input type='text' name='somewords' size='24'/> <input type='submit' value='submit'/> </form> Form Processing Script on formprocesser.php: <?php $gotWords = $_GET['somewords']; echo "The words from the form (page #1) that went through the URL are \"$gotWords\""; ?> Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/#findComment-284845 Share on other sites More sharing options...
Jewbilee Posted June 28, 2007 Share Posted June 28, 2007 Skunk, that isnt what hes asking. Hodo, what you're trying to use is $_GET functions. When you have a url such as: http://www.myspace.com/myfile.php?userid=10 it is possible to retrieve "userid"'s value using a the $_GET function. in the myfile.php code, you would have something like this: $userid = $_GET['userid']; That takes the value for userid from the url and assigns it to a new variable. (Note: the variable names can be whatever you want). You would then use this to load whatever info you want. Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/#findComment-284848 Share on other sites More sharing options...
Hodo Posted June 28, 2007 Author Share Posted June 28, 2007 Thanks all thats making more sense. In my php file I have a $_POST[] that "gets" values from my winsock. Will $_GET[] do the same thing? I wanted to call this php file from a browser to cause it to perform different tasks. I have a case/switch in the file and this is a command code so www.myplace.com/file.php?code=3 tells it to do something I want. Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/#findComment-285183 Share on other sites More sharing options...
corbin Posted June 28, 2007 Share Posted June 28, 2007 switch($_GET['do']) { case '1': echo 'got do 1'; break; case '2': echo 'got do 2'; break; default: echo 'got a do that isn\'t 1 or 2'; break; } If that file was accessible at http://somesite.com/do.php you could put http://somesite.com/do.php?do=1 and it would say 'got do 1'. You could go to http://somesite.com/do.php?do=3 and it would say 'got a do that isn't 1 or 2'. I hope you get how that works.... Quote Link to comment https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/#findComment-285193 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.