Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP location - where am I going wrong

Status
Not open for further replies.

rvr1

Programmer
Feb 6, 2004
16
NL
I have the following line of code:

include ('Location: description.php?prod_id=$product_id');

but I receive the error:

Warning: main(Location: description.php?prod_id=$product_id): failed to open stream: No such file or directory

I think it is obvious to see what I am trying to do - open a new file with the contents varying upon the contents of prod_id.

Please can anyone let me know how I should achieve this. I'm still new to all this.

Many Thanks!
 
include does not require ttaht you specify 'Location: '
so that would mean your line should be
include('description.php?prod_id=$product_id')

then, you will only include the source code of the page, not the compled one, therefore you cannot use parameters like 'prod_id=$product_id'. instead you can either use
Code:
$prod_id = $product_id;
include('description.php')
and use $prod_id from description.php as if it were a local variable or you can use $product_id directly as a local variable in description.php

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
I think you are maybe thinking of the:
Code:
if(isset($product_id)) {
  $goto = "/redirect/here.php?procuct_id=$product_id";
  header("HTTP/1.1 301 Moved Permanently");
  header('Location: ' . $goto);
}

or, if you want to include, it's right what DaZZled said:
you cannot include like you trid!

eg.
Code:
include(/redirect/here.php);

if you are to include, the included file will enherit all variables from the including document..

eg. if you have index.php and include the blah.php, blah.php will have access to all variables in index.php

therefore, it's important that you do not over-write any important variables for your script to work.

ps. If you use forms for submitting, you can submit to self and incude, or you can submit to other script.

If your included file is only meant for including, check the $_SERVER['PHP_SELF'] != <name of included file>

eg.
Code:
if $_SERVER['PHP_SELF'] != <name of included file>
  do the code
else
  do nothing
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top