Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Require and Include GET

I would like to require a file but also pass GET variables through the url, but when I write:

<?php
   require_once("myfile.php?name=savagewood");
?>

I get a fatal error. How would I accomplish this functionality in a different way, such that I don't get a fatal error?

like image 345
NoodleOfDeath Avatar asked Apr 24 '11 17:04

NoodleOfDeath


2 Answers

variables will be available as normal you do not have to pass like this.

$name='savagewood';
require_once("myfile.php");

$name will be available in myfile.php

like image 148
Shakti Singh Avatar answered Oct 05 '22 22:10

Shakti Singh


<?php
$getVarsArray = $_GET;
$postVarsArray = $_POST;
/* n number of variables and lines of code*/
include('script-a.php');
?>

Now in script-a.php has access to $getVarsArray and $postVarsArray and if in any case you are in doubt you can use $GLOBALS to access any variable throughout the life cycle of a script. But using global variables is a sin. :)

like image 31
Kumar Avatar answered Oct 06 '22 00:10

Kumar