[PHP] Whats Wrong With This

Socius Decennalis
Decennium
Joined
May 11, 2008
Messages
513
Reaction score
99
PHP:
<?
    $p = $_GET['p']
    if($p == "rpc" || $p == "lol"){
    if($p == "rpc"){
        include('test.php');
            } elseif($p == "lol"){
            include ('lol.php');
            } else {
            {
            exit;
//Begin Getting Stuff Like index.php?home
?>
Comes Up With This Error
Code:
Parse error:  syntax error, unexpected T_IF in /MYURL/ on line 16
 
Re: ][Whats Wrong With This][

Curly bracket before exit is facing the wrong way. And
PHP:
$p = $_GET['p']
needs to terminate with a semi-colon.
 
Re: ][Whats Wrong With This][

Syntax incorrect.

PHP:
<?php
$p = $_GET['p']
if($p == "rpc" || $p == "lol")
{
	if($p == "rpc")
	{
		include_once('test.php');
	} 
	else if($p == "lol")
	{
		include_once('lol.php');
	} 
	else 
	{
		include_once('test.php');
	}
}
?>
 
Re: ][Whats Wrong With This][

PHP:
<?php
if($_GET['p'] == "rpc") {
	include_once('test.php');
} elseif($_GET['p'] == "lol") {
	include_once('lol.php');
} else {
	include_once('test.php');
}
?>

or

PHP:
<?php
if($_GET['p'] == "lol") {
	include_once('lol.php');
} else {
	include_once('test.php');
}
?>

since rpc is the same as else rpc isnt really needed.
 
Re: ][Whats Wrong With This][

What's right with it really? :S

PHP:
<?php
switch($_GET['p']){
	case rpc:
		include("test.php");
	break;
	case lol:
		include("lol.php");
	break;
	//Etc
}
?>
 
Re: ][Whats Wrong With This][

Yeah,
Case also works fine :D.

Edit:
Just to annoy you guys,
If you are giving the pages the same name as varible p,
You could use this just place the pages in directory includes and trow a htaccess in it.
PHP:
<?
if(empty($_GET['p']) or !preg_match('/^[A-Za-z0-9]+$/',$_GET['p'])) {
	$_GET['p'] = "home";
}
if(!file_exists("includes/" . $_GET['p'] . ".php")) {
	$_GET['p'] = "home";
}
include_once "includes/" . $_GET['p'] . ".php";
?>
There probably are better ways but this works 2 :D.
 
Re: ][Whats Wrong With This][

Okay Im Using
PHP:
switch($_GET['page']){
    case home:
        include("includes/home.php");
    break;
    case forum:
        include("includes/forum.php");
    break;
	case maintenace:
        include("includes/forum.php");
    break;
    //Etc
}
That Code.
And I Just Want One Page To Show At A Time.
How Would That Work?
 
Re: ][Whats Wrong With This][

Err that code only shows 1 page at a time.
Heres My Index.
PHP:
<?php
switch($_GET['page']){
    case home:
        include("includes/home.php");
    break;
    case forum:
        include("includes/forum.php");
    break;
	case maintenace:
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
include("index.php?maintenance");
exit;
}
else {
}
if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://~~/index.php?page=home\"\" />";
exit;
}
else {
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=~~~\"\" />";
exit;
}
else {
}
?>
 
Re: ][Whats Wrong With This][

PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
include("index.php?maintenance");
exit;
}
else {
}
if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://~~/index.php?page=home\"\" />";
exit;
}
else {
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=~~~\"\" />";
exit;
}
else {
}
?>

You forgot to make strings of the cases
 
Re: ][Whats Wrong With This][

PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
include("index.php?maintenance");
exit;
}
else {
}
if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://~~/index.php?page=home\"\" />";
exit;
}
else {
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv=\"refresh\" content=\"0;URL=~~~\"\" />";
exit;
}
else {
}
?>

You forgot to make strings of the cases
How Would I Add The Maintenace Page.
With The IF's
 
Re: ][Whats Wrong With This][

PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
header("Location: index.php?page=maintenance");
exit;
}
else {
}
if ($_SERVER['REQUEST_URI'] == "/") {
header("Locaiton: index.php?page=home");
exit;
}
else {
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
header("Locaiton: ~~~");
exit;
}
else {
}
?>
 
Re: ][Whats Wrong With This][

PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
header("Location: index.php?page=maintenance");
exit;
}
else {
}
if ($_SERVER['REQUEST_URI'] == "/") {
header("Locaiton: index.php?page=home");
exit;
}
else {
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
header("Locaiton: ~~~");
exit;
}
else {
}
?>
Warning: Cannot modify header information - headers already sent by (output started at /home/alpha/public_html/beta/includes/home.php:1) in /home/alpha/public_html/beta/index.php on line 16
 
Re: ][Whats Wrong With This][

Then.. theres some code echoed before that ?
PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=maintenance' />");
exit;
}

if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=home' />");
exit;
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv='refresh' content='0;URL=~~~' />");
exit;
}
?>

You also don't need extra
PHP:
else {
}
Those are unnecessary.
 
Re: ][Whats Wrong With This][

Then.. theres some code echoed before that ?
PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=maintenance' />");
exit;
}

if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=home' />");
exit;
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv='refresh' content='0;URL=~~~' />");
exit;
}
?>

You also don't need extra
PHP:
else {
}
Those are unnecessary.
done that. btw, when it echos to maintenace page. it just keeps redirecting.
 
Re: ][Whats Wrong With This][

Oops, my bad!

PHP:
<?php
switch($_GET['page']){
    case 'home':
        include("includes/home.php");
    break;
    case 'forum':
        include("includes/forum.php");
    break;
    case 'maintenance':
        include("includes/forum.php");
    break;
    //Etc
}

if ($site['maintenance'] == "1") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=maintenance' />";
exit;
}

if ($_SERVER['REQUEST_URI'] == "/") {
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=home' />";
exit;
}

if ($_SERVER['REQUEST_URI'] == "/index.php") {
echo "<meta http-equiv='refresh' content='0;URL=~~~' />";
exit;
}
?>
 
Back