Jump to content

Variable Overstepping Its Boundaries!


Hartley

Recommended Posts

[code]<?php

if (!$p || $p == "" || $p == "latest") {
    $p = "latest";
}

?>[/code]

Very simple: if someone goes to the site without declaring a page variable, it will automatically bring them to the "Latest News" page (I use $p with includes). It's worked like a charm for a while, until now:

I'm working on integrating vBulletin and my site, and I have come across a problem: it's declaring EVERYTHING as latest. I tried adding an else statement to say $p = $p, but it's proven useless. Is there a function that may disable this? I can't post any additional code due to legality reasons (and the fact that it's so many lines).

http://www.sedition-gaming.com/test/index.php

I realize this is vague, but I hope there's an off chance someone may have had this issue before.
Link to comment
https://forums.phpfreaks.com/topic/34176-variable-overstepping-its-boundaries/
Share on other sites

[quote]it's declaring EVERYTHING as latest[/quote]

No idea what that meens but, you should be using the $_GET array if this is meant to be comming through the url.

[code]
<?php
  if (!$_GET['p'] || $_GET['p'] == "" || $_GET['p'] == "latest") {
    $p = "latest";
}
[/code]
Fixed that (thanks), but still getting the same error.

If I put the code at the very top of a page, it will declare $p as "latest" for EVERYTHING... except if $p=latest (the opposite of what it should do, except for the $p="".

I wish I could just put PHP code inside a vBulletin template and use that :(
If $p is "latest", what does it declare $p as?

You can simplify it to

[code=php:0]if (empty($_GET['p])) {
  $p = 'latest';
} else {
  $p = $_GET['p'];
}[/code]


Logically that code will produce the same output, but it's a little neater :)  It'll also set $p from $_GET['p'] in all cases.

Archived

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

×
×
  • Create New...

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.