Jump to content
xisto Community
Sign in to follow this  
Amezis

Include File.php?id=something using the include() function

Recommended Posts

Well, I am making a full CMS system for my site, and want to make the index.php file to include the view.php?id=1 file. I tried with this code, but it didn't work:

<?php include 'view.php?id=1' ?>

This is the error I get:
Warning: main(view.php?id=1) [function.main]: failed to open stream: Invalid argument in C:\server\xampp\htdocs\test\index.php on line 1Warning: main() [function.include]: Failed opening 'view.php?id=1' for inclusion (include_path='.;C:\server\xampp\php\pear\') in C:\server\xampp\htdocs\test\index.php on line 1

So what can I do?

Share this post


Link to post
Share on other sites

Start by using the function in the correct form.
The brackets are required for Include functions to define the target of the file to 'Include'.

<?php include('header.html') ?>

Share this post


Link to post
Share on other sites

Actually, include "bla.php"; is a perfectly good way of including a file.

 

Here's how to fix the problem:

First Open view.php

 

Find:

 

if ($_REQUEST["id"] == "1")

And change it to:

 

if ($view_var == 1)

Secondly open index.php

 

Find:

 

include 'view.php?id=1';  

And above that add

 

$view_var = 1;

And that's it :)

 

==========================================

 

The reason why it doesn't work is because php looks for the file view.php?id=1 on the filesystem not view.php.

Share this post


Link to post
Share on other sites

<?php include 'header.html' ?>

225096[/snapback]

Well, I'll be darned... it does so work. Thanks for the lesson. Syntax can be so picky about these things sometimes, it was something that I thought might help.

Share this post


Link to post
Share on other sites

This is the error I get:

Warning: main(view.php?id=1) [function.main]: failed to open stream: Invalid argument in C:\server\xampp\htdocs\test\index.php on line 1

 

What's on line 1 of index.php?

Share this post


Link to post
Share on other sites

Okay then, in view.php change:

$id = $_REQUEST['id'];

To:

$id = $view_var;

And also, I forgot to add in the last post.

Change this in index.php:

include 'view.php?id=1'

To:

include 'view.php';

And making the changes shown in my last post in this topic, your problem should be fixed.

edit: fixed typos
Edited by cmatcmextra (see edit history)

Share this post


Link to post
Share on other sites

Just to avoid future problems, I would recommend changing:

 

$id = $_REQUEST['id'];

To somethingl ike:

 

$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : isset($view_var) ? $view_var : 0;
.

 

Changing to just '$id = $view_var;' means it won't work if someone actually accesses view.php directly. Whether or not that's going to happen in your particular circumstance I don't know, but I like to try to avoid potential problems wherever possible.

Share this post


Link to post
Share on other sites

Ooooh, pick me! try this:

<? include("http://yoursite.trap17.com/view.php?id=1"); ?>
I saw in a tutorial somewhere not to do that while including a file on the serverr, because it would produce the output that would be sent to the browser if the user would request it manually. Give it a try.

Share this post


Link to post
Share on other sites

Hmm, whilst that would work (provided no variables require global usage etc), I wouldn't recommend it. It basically requests the file from the server, which a) consumes bandwidth, B) is simply a poor coding practice, and c) severly limits the script's functionality and capability.

Share this post


Link to post
Share on other sites

Hmm, whilst that would work (provided no variables require global usage etc), I wouldn't recommend it. It basically requests the file from the server, which a) consumes bandwidth, :rolleyes: is simply a poor coding practice, and c) severly limits the script's functionality and capability.

 

Yeah, but it accomplishes what [i forgot his name who started this topic] wanted to do, passing a variable to the other script through a quertstring variable.

Share this post


Link to post
Share on other sites

Isn't the correct use of include isinclude("filename.php"); ?I allways get error when using include with parameter like :include("filename.php?get=1");Because php read that as open a 'filename.php?get=1' file that you dont have. But you only have 'filename.php'

Share this post


Link to post
Share on other sites

Why you are trying to access include file with get variable. Include method fetches the full code of the file you are trying to access without its execution. Then the place where include function is implemented is replaced with the code fetched from the file. Only after that, PHP Parser executes the file. So it is meaningless to use variables on include files.

Share this post


Link to post
Share on other sites

Can someone help me I'm also trying to get php include using php?id=


<?php include("myspace.php?id=108001502"); ?>

here a code i used on my myspace.php
<object type="application/x-shockwave-flash" data="http://mediaservices.myspace.com/services/media/embed.aspx/m=<?php echo $_GET["id"]; ?>"  width="593" height="465"><param name="movie" value="http://mediaservices.myspace.com/services/media/embed.aspx/m=<?php echo $_GET["id"]; ?>" /><param name="quality" value="high" /><param name="scale" value="noorder" /><param name="wmode" value="transparent" /><param name="allowscriptaccess" value="never" /><param name="allownetworking" value="internal" /><param name="allowfullscreen" value="true" /></object>

Error Message
Warning: include(myspace.php?id=108001502) [function.include]: failed to open stream: No such file or directory in /home/web/domains/website.com/public_html/video/index.php on line 56Warning: include() [function.include]: Failed opening 'myspace.php?id=108001502' for inclusion (include_path='.:/usr/local/lib/php') in /home/web/domains/website.com/public_html/video/index.php on line 56

Edited by tokyosama (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.