Jump to content

Archived

This topic is now archived and is closed to further replies.

meamrussian

PHP Help Needed

Recommended Posts

Sorry about the undescriptive title. I couldn't think of the name of my problem.

I bought a MySpace friend train script, and I seem to be getting a problem.

[a href=\"http://www.mshangout.com/train/index.php\" target=\"_blank\"]http://www.mshangout.com/train/index.php[/a]

This is the error:

[code]Warning: main(pages/.php): failed to open stream: No such file or directory in /home2/meamruss/public_html/train/pages.php on line 11[/code]
This is line 11:
include "pages/" . $page . ".php";

Throughout the whole script files, there is no such variable $page. However, the index page has only the following content:
<meta http-equiv="refresh" content="0;url=pages.php?page=home">

I'm guessing that "home" is $page in this case. The header (Home Page | Join the Train | What is the Train?) links have this format:
<a class="link_whitetored" href="pages.php?page=faq">FAQ</a>

Obviously, it assumes that it should load what's after the = for $page. But why isn't it reading what's after this = sign? It's just giving me pages/.php.

Sorry if that was confusing.

Thanks in advance.

Share this post


Link to post
Share on other sites
The problem is that this is probably an old script and uses outdated techniques for managing $_GET variables.

There used to be a setting called register_globals which meant that if you send a variable through the URL (as page.php?variable_name=variable_value ) in page.php the $variable_name variable will already be automatically set. There was no need to get it from the $_GET array. In your case $page is the variable that the script expects to be automatically set.

This functionality has since been removed (for security reasons i think) so you have to set $page manually by extracting it from the $_GET array. Add:

[code]$page = $_GET['page'];[/code]

somewhere above the include line and it should work.

Share this post


Link to post
Share on other sites
Aha! That's the problem. It's using global variable. However, there is another part in the script that uses $post with POST instead of GET. How can I put them both in? I can't just put in

$page = $_GET['page'];
$page = $_POST['page'];

How can I use both?

Thanks.

Share this post


Link to post
Share on other sites
The problem with this method is that you are adding $_GET['page'] to the end of $page and then $_POST['page'] to the end of $page so if the variable $page already exists it may not come out how you expected. Your way is very simple and works, but you should keep this in mind in the event you run into a problem with this in the future.

[code]if ( $_SERVER['REQUEST_METHOD'] == "GET" ) $page = $_GET['page'];
if ( $_SERVER['REQUEST_METHOD'] == "POST" ) $page = $_POST['page'];[/code]

or

[code]if ( isset($_GET['page']) ) $page = $_GET['page'];
if ( isset($_POST['page']) ) $page = $_POST['page'];[/code]

Just some food for thought.

Share this post


Link to post
Share on other sites
Guest footballkid4
Or:
[code]$page['GET'] = isset( $_GET['page'] ) ? $_GET['page'] : "";
$page['POST'] = isset( $_POST['page'] ) ? $_POST['page'] : "";[/code]

Then you can do things based on which one is set

Share this post


Link to post
Share on other sites
Now you have three examples. lol...Anyone else think of some more?

Share this post


Link to post
Share on other sites
yes here is another example lol

[code]

if($_GET['page']==true){
echo "your Code here";
}
if($_POST['page']==true){
echo "your Code here";
}

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

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.