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
Share on other sites

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

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.