call index.php with variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

call index.php with variables

Post by markosjal »

I have a need to call index.php with some variables from another file
Like index.php/?cat=18

I have tried an include and this did not work.


From what I understand I need a block variable


I am looking for some sample code if anyone knows how to do this
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: call index.php with variables

Post by JakeJ »

Actually, that would be index.php?cat=18. You have an extra slash in there.

Have you though about using sessions?

What happened when you tried to use an include?

Post some code and any error messages.
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: call index.php with variables

Post by markosjal »

I am using this almost exactly on another site
Except for the second line which on the other site needs no URL Variable. Because it does not work on this site I looked around on the web and found various references to this inability to pass url variables this way in an include.

Code: Select all

<?php include 'header.php' ; ?>
<?php include 'index.php?cat=4' ; ?>
<?php include 'footer.php' ; ?>

the error is that it can not open that file / stream
Last edited by Benjamin on Tue May 18, 2010 4:39 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: call index.php with variables

Post by JakeJ »

It sees ?cat=4 as part of the file name.

Check out this URL, it will probably work for you: http://inkgrass.lazymoon.org/2007/11/12 ... p-include/
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: call index.php with variables

Post by markosjal »

Yes that worked and thanks so much!
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: call index.php with variables

Post by JakeJ »

I ask my fair share of questions on here, it's nice to be able to help out someone else.
Post Reply