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

user1314404
  • 1,253
  • 3
  • 22
  • 51
  • 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. – user1314404 Aug 14 '13 at 04:17

2 Answers2

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
}
Daniel
  • 4,816
  • 3
  • 27
  • 31
  • 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 ? – user1314404 Aug 14 '13 at 04:11
  • 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 – user1314404 Aug 14 '13 at 04:40
  • You got it! Cheers. It was unclear whether you would add a value to the url parameter. – Daniel Aug 14 '13 at 13:20
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.

TroyCheng
  • 571
  • 3
  • 10
  • 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. – user1314404 Aug 14 '13 at 04:05