Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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