Jump to content

Send data to php from browser url


Hodo

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/57547-send-data-to-php-from-browser-url/
Share on other sites

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\"";
?>

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.

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.

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.