Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Include File.php?id=something


14 replies to this topic

#1 Amezis

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 535 posts
  • Location:Oslo, Norway

Posted 29 January 2006 - 06:08 PM

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 1

Warning: 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?

#2 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 29 January 2006 - 06:57 PM

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') ?>


#3 electriic ink

    "Britons never never shall be slaves." As true now as it was in 1740.

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,262 posts
  • Gender:Male
  • Location:Heaven
  • Interests:Promotion: Aug 4 2005 8.24pm BST
  • myCENT:74.43

Posted 29 January 2006 - 07:13 PM

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.

#4 Amezis

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 535 posts
  • Location:Oslo, Norway

Posted 29 January 2006 - 08:24 PM

cmatcmextra, I don't have if ($_REQUEST["id"] == "1") in view.php. This is what I have:
$id = $_REQUEST['id'];


#5 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 29 January 2006 - 09:05 PM

jlhaslip, on Jan 29 2006, 11:57 AM, said:

<?php include 'header.html' ?>

View Post

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.

#6 Tyssen

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,161 posts
  • Location:Brisbane, QLD

Posted 29 January 2006 - 10:22 PM

Amezis, on Jan 30 2006, 04:08 AM, said:

This is the error I get:[code]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?

#7 electriic ink

    "Britons never never shall be slaves." As true now as it was in 1740.

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,262 posts
  • Gender:Male
  • Location:Heaven
  • Interests:Promotion: Aug 4 2005 8.24pm BST
  • myCENT:74.43

Posted 30 January 2006 - 08:18 AM

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, 30 January 2006 - 08:24 AM.


#8 Amezis

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 535 posts
  • Location:Oslo, Norway

Posted 30 January 2006 - 01:25 PM

Thanks! It works now :)

#9 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 30 January 2006 - 03:36 PM

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.

#10 michaelper22

    -=Hybrid Bus=-

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 742 posts
  • Gender:Male
  • Location:My hybrid bus (in NYC), a computer
  • Interests:Not interested in anything
  • Spam Patrol

Posted 02 February 2006 - 02:26 AM

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.

#11 Spectre

    Privileged Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 873 posts

Posted 02 February 2006 - 09:52 AM

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.

#12 michaelper22

    -=Hybrid Bus=-

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 742 posts
  • Gender:Male
  • Location:My hybrid bus (in NYC), a computer
  • Interests:Not interested in anything
  • Spam Patrol

Posted 03 February 2006 - 02:17 AM

View PostSpectre, on Feb 2 2006, 04:52 AM, said:

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.

#13 silentwind

    Newbie

  • Kontributors
  • Pip
  • 7 posts

Posted 03 February 2006 - 10:52 AM

Isn't the correct use of include is
include("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'

#14 ivenms

    Member [Level 1]

  • Kontributors
  • PipPipPipPip
  • 52 posts

Posted 03 May 2008 - 04:46 PM

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.

#15 tokyosama

    Newbie

  • Kontributors
  • Pip
  • 1 posts

Posted 24 December 2011 - 01:33 PM

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 56
Warning: 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, 24 December 2011 - 01:45 PM.





Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users