PDA

View Full Version : Error (PHP)



loserWILL
15-07-2008, 05:17 PM
I'm getting this error, I don't know why.


Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/kolzy/public_html/picster/index.php on line 34Line 34:

$1 = $_GET[home];+rep

Never mind, now I have a new problem. I've got the following code, and it changes the whole page.


<?php

if ($_GET[home]){
echo "home nav";
};
exit;

if ($_GET[pv]){
echo "pv nav";
};
exit;

if ($_GET[reg]){
echo "reg nav";
};
exit;

?>

http://www.omgupload.com/files/1494wha.png
(that's what it makes my page look like)

Invent
15-07-2008, 05:24 PM
A variable can't be completely numeric.

Use something like $a1 instead.

loserWILL
15-07-2008, 05:27 PM
Thanks, read my new question though.

iUnknown
15-07-2008, 05:38 PM
Doesn't look right... it'll stop the page from loading after doing any of those... and it'll only do the top one if $_GET[home] exists.... try recoding it.

loserWILL
15-07-2008, 05:46 PM
I've tried, I just don't understand what's wrong wiht it. Anyone?

Blob
15-07-2008, 05:55 PM
Dont use ; after a }

Excellent
15-07-2008, 05:56 PM
Dont use ; after a }Exactly what he said.

loserWILL
15-07-2008, 05:59 PM
<?php

if ($_GET['home']){
echo "home nav";
}

if ($_GET['pv']){
echo "pv nav";
}

if ($_GET['reg']){
echo "reg nav";
}

?>

Even with that it still gives me the white page.

Source
15-07-2008, 06:04 PM
<?php

if ($_GET['page'] === "home"){
echo "home nav";
exit;
}

if ($_GET['page'] === "otherpagename"){
echo "home nav";
exit;
}

if ($_GET['page'] === "otherpagename2"){
echo "home nav";
exit;
}

// Dunno why on earth you have exits
// You can also use switches

switch($_REQUEST['page']){
case "home":
echo "home nav";
break;
case "diffpage":
echo "asdasdads";
break;
case "diffpage":
echo "dsadsadsasda";
break;
case default:
echo "No page requested";
break;
}
?> www.yoururl.com/index.php?page=whatever (http://www.yoururl.com/index.php?page=whatever)

Blob
15-07-2008, 06:10 PM
<?php

if ($_REQUEST['page'] === "home"){
echo "home nav";
exit;
}

if ($_REQUEST['page'] === "otherpagename"){
echo "home nav";
exit;
}

if ($_REQUEST['page'] === "otherpagename2"){
echo "home nav";
exit;
}

// Dunno why on earth you have exits
// You can also use switches

switch($_REQUEST['page']){
case "home":
echo "home nav";
break;
case "diffpage":
echo "asdasdads";
break;
case "diffpage":
echo "dsadsadsasda";
break;
case default:
echo "No page requested";
break;
}
?> www.yoururl.com/index.php?page=whatever (http://www.yoururl.com/index.php?page=whatever)

I always use $_REQUEST, to get it from the URL. dunno why, probs a bad way todo it.

Isnt $_REQUEST both POST and GET?

Source
15-07-2008, 06:13 PM
Woops yea its meant to be $_GET as $_REQUEST has security holes in as it can get from cookies aswel.

Edit// Fixed, and don't quote whole posts, it looks a complete mess.

Decode
15-07-2008, 06:18 PM
if ( isset ( $_GET['page'] ) ) {
$file = "content/" . $_GET['page'] . ".php";
if ( file_exists ( $file ) ) {
include ( $file );
}
else {
include ("404.php");
}
}
else {
echo ( "Epic fail: No GET was set." );
}


Thats probs the best way to do it. Simply add all your pages to /content/ then save that as index.php and include files by using; index.php?page=filenamewithoutdotphpontheend

Source
15-07-2008, 06:22 PM
I highly disagree with you on that method. Seems like a lazy way and makes your webserver completly unsctructured. Well... in my eyes.

Blob
15-07-2008, 06:39 PM
I highly disagree with you on that method. Seems like a lazy way and makes your webserver completly unsctructured. Well... in my eyes.

No its easier instead of having to list every php file on there...

Source
15-07-2008, 06:54 PM
Not if your doing it from a database...

loserWILL
15-07-2008, 06:56 PM
Thanks Matt, I'm using an edited version of your code. But it's still making my whole page white. Anybody know what's up with that?

EDIT: Don't worry about that.

Excellent
15-07-2008, 06:58 PM
What is it you're getting?

Decode
15-07-2008, 07:00 PM
Thanks Matt, I'm using an edited version of your code. But it's still making my whole page white. Anybody know what's up with that?

Remove all the exit's

Blob
15-07-2008, 07:03 PM
Not if your doing it from a database...

Anyone that withdraws from a database always uses a cleaning method, unless they are dumb.

Tomm
15-07-2008, 07:09 PM
Highly insecure do NOT use this. You can transverse other directories using this and get files in those directories that you may not want users to see.




if ( isset ( $_GET['page'] ) ) {
$file = "content/" . $_GET['page'] . ".php";
if ( file_exists ( $file ) ) {
include ( $file );
}
else {
include ("404.php");
}
}
else {
echo ( "Epic fail: No GET was set." );
}
Thats probs the best way to do it. Simply add all your pages to /content/ then save that as index.php and include files by using; index.php?page=filenamewithoutdotphpontheend

Source
15-07-2008, 07:14 PM
Yea, didn't see that at first glance. But you absolutely could.

And Blob of course you would use a cleaning function... but that's obvious. Your just trying to be awkward now.

Blob
15-07-2008, 07:17 PM
Yea, didn't see that at first glance. But you absolutely could.

And Blob of course you would use a cleaning function... but that's obvious. Your just trying to be awkward now.

No, I'm not being awkward I'm just saying overall that is a better method to use even with SQL as you can easily use a function.

Decode
15-07-2008, 07:22 PM
Highly insecure do NOT use this. You can transverse other directories using this and get files in those directories that you may not want users to see.
I might be wrong, but couldn't you only get to files and folders in the /content/ dir?

Source
15-07-2008, 07:29 PM
without it been filtered you could probably work your way in a new file path by closing off the previous, or even run a mysql query.

Want to hide these adverts? Register an account for free!