Forum Moderators: coopster

Message Too Old, No Replies

Complex PHP Include () w/ Variables

Complex PHP Include () w/ Variables

         

m_ike842

7:49 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



So I have this website im working, and I have all the links > Ie. index.php?PAGE=news.php?article=1&comments=1

Im using the php include to get that $PAGE in the url.
So Far its workign well, but for some reason its only catching "index.php?PAGE=news.php?article=1" and everything after the "&" is being cut off, any ideas?

WesleyC

8:04 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



Would it be possible to rethink your architecture?

That system sounds very awkward and clunky. Can you do something like "index.php?page=news&article=1&comments=1"? This would make your system more secure (make sure to error on or strip out any characters such as "." and "/" in your page variable, otherwise you're just begging for someone to try hacking your site). This should also solve the problem you're having with the second? in the URL.

m_ike842

8:10 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



I cant really do it that way, the way I originally had it I was using an iframe, decided to switch it all over today.

But, everything works fine... I used the full word variable to give you an example, but yea im using the index.php as a basic template and Im using php Include to include the other pages ie.. news.php , archives.php.. etc... So it all works well but the variables after the & keep getting cut off and I have no clue why.

So when I have a link thats directed to
index.php?page=news.php?id=1&comment=0

Its only coming out as
index.php?page=news.php?id=1

So its reading the first variable but everything after that & is just getting cut off :S

m_ike842

8:38 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



Ok so I just realized

The reason $page isnt picking up the entire "index.php?PAGE=news.php?article=1&comment=1" is because the original index.php?Page is picking up "news.php?aritcle=1" and since it hits the & its recognizing it as another variable.

Anyway i can have the page variable pick up the entire line

PHP_Chimp

9:09 pm on Oct 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Seeing as you want the complete query string then you can use $_SERVER['QUERY_STRING'] to give you everything after the?.

You will need to split that up into whatever bits you want. The other option is change it so you have everything in $_GET variables i.e.

index.php?PAGE=news.php change? for & article=1&comments=1
Then everything is available in $_GET

m_ike842

9:30 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



Would $_SERVER['QUERY_STRING'] read the string as variables?

PHP_Chimp

9:50 pm on Oct 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No it just returns a string of everything after the?
So you would then need to break it up yourself into the bits that you want.

[edited by: PHP_Chimp at 9:51 pm (utc) on Oct. 14, 2007]

m_ike842

9:57 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



yea nvm, that one didnt work, im gonna try taking out the? and im gonna do some experimenting see what i can get.

m_ike842

10:02 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



alright so hears the latest info:

I figured out that I can get that stored variables thats passed through the link the & over? did work, now the only problem im having now is that the Included file cant get those variables... I can get them to come up onthe document holding the php include, but not the included file

PHP_Chimp

10:05 pm on Oct 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to pass the variables back to the included file. As those variables are not part of that file, just the page it is getting included on.

m_ike842

10:10 pm on Oct 14, 2007 (gmt 0)

10+ Year Member



how do i do that?

PHP_Chimp

7:58 pm on Oct 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your include file needs the PAGE in one of its variables then lets assume that in the include file that variable is $page.

$_GET['PAGE'] = $page;

It all depends on what is in the included file and how you are using that included file i.e. if your included file is just there to provide output, but doesn't take any input then you cant pass the variables over. If your included file takes input then you can pass variables back to it the same way you would pass anything back to that script.

m_ike842

9:44 pm on Oct 15, 2007 (gmt 0)

10+ Year Member



Im not sure why,,,, but even when using the $_GET... the included page isnt not picking up those variables, but page that has the include script is getting that variable :S

http://example.com/index.php4?pa=home.php

http://example.com/index.php4?pa=news.php?s=1&c=1&page=17

[edited by: coopster at 10:18 pm (utc) on Oct. 15, 2007]
[edit reason] examplified, no personal urls please [/edit]

m_ike842

1:19 am on Oct 16, 2007 (gmt 0)

10+ Year Member



Ive been doing some more experimenting with this one...

I've noticed some weird things, with in these pages I have a news system I developed...

both the news.php and home.php page,,, Now my news system works and all, now in one of hte "articles" to test i made a while ($t<100) script , on the home.php it works and echos 1-100; but on the news.php page it comes up as >> "; }?> << with out hte <<>>'s im really stumped now... its the same mysql/php display code too

vijaynair

2:17 am on Oct 16, 2007 (gmt 0)

10+ Year Member



First of all, you should remove the second '?' from query string.

Replace it with '&'. IT should look like

index.php?PAGE=news.php&article=1&comments=1.

THen pass on the article and comment variables.

m_ike842

2:29 am on Oct 16, 2007 (gmt 0)

10+ Year Member



vijaynair, yea I did do that , forgot to mention that I did that in the last post,