-2

I have a script, let's call it myScript.php. It's one of several scripts.

I want to pass certain things to it via the HTTP address, like this: …/myScript.php?format=xml&action=courses where xml is the format and the action is a query some courses in my database.

But I want also to be able to assign …/myScript.php?format=json&action=courses in the same script.

How can I do this?

Ivar
  • 6,138
  • 12
  • 49
  • 61
Andrew Steier
  • 133
  • 1
  • 10

2 Answers2

1

You can reference any parameters passed in the url like so in php: $_REQUEST['format'], $_REQUEST['actions']. You can then assign them to a variable and change that variable in your script.

fetch('./myScript.php?format=xml&action=courses')

$_REQUEST['format'] //xml
$_REQUEST['actions'] //courses

REQUEST is the general method but you can also use GET. Refer to this for more info: https://stackoverflow.com/a/1924958/11945488

Anton Bks
  • 482
  • 3
  • 10
0

$_REQUEST=array_merge($_POST,$_GET,$_COOKIE);

in native php global request variable include get post and cookie ..

You should get parameters with global variable $_GET, if you does $_REQUEST maybe can confusion php

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28