|
| 11 Oct 2011 09:35 PM |
Can you put 'GET's on URLs for require_once(), such as
require_once(something.php?id=1);
I'm asking this from a PHP perspective. |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Oct 2011 09:40 PM |
In PHP's require_once() function, can you put extras onto the URL? Here's an example:
require_once("cool.php?coolness=1337");
Can you do that, or will it cause an error if you put the '?coolness=1337' on it? |
|
|
| Report Abuse |
|
|
belial52
|
  |
| Joined: 10 Oct 2009 |
| Total Posts: 8074 |
|
|
| 11 Oct 2011 09:57 PM |
| I don't see why you couldn't. Test it before you come here though, please. |
|
|
| Report Abuse |
|
|
|
| 11 Oct 2011 10:05 PM |
| I did. I got an error. I was more so coming to see if it was just me or if it was really because I can't be done. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 12 Oct 2011 12:33 AM |
| What? It doesn't make any sense to pass that data to a require. A require is a _textual inclusion_, what do you pospose the said GET parameters are going to do exactly...? |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2011 07:22 AM |
@xLEGOx
maybe he wants to grab $_GET's from another page source? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 12 Oct 2011 07:45 AM |
Why would you do something so horribly inefficient (And incorrect) when you could just directly pass the data in with a variable?
You can Do that (Not with require, since that's not what require is for), but it would be very bad design to do so. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2011 08:40 AM |
| How can I pass data into an exterior file, xLEGOx? I'm new to PHP, so I guess that's something I have yet to learn. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 12 Oct 2011 11:04 AM |
You have two options:
file1.php:
$sum = $a + $b
file2.php
$a = 1 $b = 2
require('file1.php')
print $sum //3
-----------------------------
file1.php:
function sum($a, $b) { return $a + $b; }
file2.php
require_once('file1.php'); print sum(1, 2); //3 |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2011 02:14 PM |
| ...I don't think you understand what I'm trying to do. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2011 02:22 PM |
| Well require() won't throw an error if you use _GET, but include() will - both of which don't function with _GET in the URL. So I doubt require_once won't. |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2011 02:24 PM |
No, you can't.
I'd personally try something like this:
define("ForceId" , 1); require_once("something.php");
then in something.php just use a ternary statement to define the id you're getting.
$id = (defined(ForceId)) ? ForceId : $_GET['id'] ;
Or something among those lines.
Regards, ~Scarfacial |
|
|
| Report Abuse |
|
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
|
| 12 Oct 2011 03:12 PM |
$_GET["some_value"] = "whatever"; require_once("derp.php"); |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 12 Oct 2011 04:35 PM |
> ...I don't think you understand what I'm trying to do.
...I don't think you understand what _you're_ trying to do. Your question doesn't make sense.
When you include a file, it behaves as if you copied and pasted the textual contents of the file into that location, outside of php tags. So when you include a PHP file, it is executed in the same scope as the page that includes it. |
|
|
| Report Abuse |
|
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
|
| 12 Oct 2011 07:31 PM |
| Or you can all shut up, as I've answered the original question. |
|
|
| Report Abuse |
|
|
|
| 13 Oct 2011 07:10 AM |
| Okay...I think I know how I can make this work now. Thanks for the help. |
|
|
| Report Abuse |
|
|