-2

Let say my code file is code.php and I can access it by :

localhost/test/code.php

Now I want if I enter address bar:

localhost/test/code.php?someparameter

it will automatically

overwrite "someparameter" string to a dummyfile.txt.

Is it possible to do it that way ?

I know we can use :

 $_SERVER['REQUEST_URI'];

to get URI but how could we add the param directly to the url and it still go to the same code file and process ??? I dont want to use java script here coz my server only support php.

1
  • thanks, but its not really duplicate. How to process the thing just by entering on url, not action on webpage. I think "@Request.QueryString" might have something to do here. Commented Aug 14, 2013 at 4:17

2 Answers 2

1

You will need to look further in writing your parameter, but it is possible to catch whether your "parameter" is set,

if (isset($_GET['parameter'])) {
  // do your thing
}
Sign up to request clarification or add additional context in comments.

3 Comments

how could we just type on url, press enter, then in the code it could know variable is set and assign param value to that variable ?
Ok, I got the answer for my question. Well it quite simple when u know it : if (isset($_GET['param'])) { // do your thing file_put_contents('dummyfile.txt',$_GET['param']); } //and at the link, just type: localhost/test/code.php?param=value
You got it! Cheers. It was unclear whether you would add a value to the url parameter.
0

You can use $_GET["parater_name"] to get the parameter from url. And you can use $_POST for parameters in post request. $_REQUEST for get,post and session parameters.

1 Comment

Its quite hard for me to imagine the solution. Do I need to declare a variable in the code, then use get to get the value then post again the value ? What I mean here is ust enter the url and it will appear the param in the text file, no need andy action on the webpage.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.