By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,450 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

$GET CMS

P: n/a
I have bought the book on advanced dreamweaver and PHP recently. I
have installed MySQL and PHP server but am getting an error on the
$GET statement show below. It says there is a problem with the
variable $GET but $GET is not a variable, I thought it came from the
page that calls the PHP file?

if(($_GET['type'])==""){

this gets an error
<?php
require_once("class/displayNews.php");
require_once("class/displayArticle.php");
require_once("class/displayMenu.php");
################################################## ##
# CMS Page Class #
################################################## ##

class Page{

var $type;
var $mainContent;
var $pageTitle;
var $menu;

function Page(){
$this->getType();
$this->createMenu();
}

function getType(){
if(isset($_GET['type'])){
if(($_GET['type'])==""){
$link = $PHP_SELF . "?type=article&menuID=0";
header("Location:" . $link);
}
if($_GET['type']=="news"){
$this->news();
}
if($_GET['type']=="article"){
$this->article();
}
}
}
Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Whilst lounging around on 2 Jul 2003 02:29:44 -0700,
ma**@presspley.com (presspley) amazingly managed to produce the
following with their Etch-A-Sketch:
I have bought the book on advanced dreamweaver

HAHAHAHAHAHA!!!!!

(Sorry... had to laugh at advanced WYSINWYG =D ).

and PHP recently. I
have installed MySQL and PHP server but am getting an error on the
$GET statement show below. It says there is a problem with the
variable $GET but $GET is not a variable, I thought it came from
the page that calls the PHP file?

if(($_GET['type'])==""){

this gets an error
<?php
require_once("class/displayNews.php");
require_once("class/displayArticle.php");
require_once("class/displayMenu.php");
################################################## ##
# CMS Page Class #
################################################## ##

class Page{

var $type;
var $mainContent;
var $pageTitle;
var $menu;

function Page(){
$this->getType();
$this->createMenu();
}

function getType(){
if(isset($_GET['type'])){
if(($_GET['type'])==""){
$link = $PHP_SELF . "?type=article&menuID=0";
header("Location:" . $link);
}
if($_GET['type']=="news"){
$this->news();
}
if($_GET['type']=="article"){
$this->article();
}
}
}

This is all a mix of globals enabled / disabled and bad coding
practice. Is this from your book!? if so, you've just wasted your
money! (and if so, was / is it a Wrox book? they do anything but
"rock" that's for sure).

$_GET[] is used where register_globals is disabled, yet you use
'$PHP_SELF' rather than $_SERVER['PHP_SELF'] too.

I suggest one or the other, $_SERVER / $_GET etc being the primary /
most secure choice.

$_GET['type'] won't be affected by the function, as the function is
never given the data to parse.

The header call is flawed too.. you're calling a relative path. This
needs[1] to be a full URL.

Some more information might be handy.. like specific error line,
specific error message....

My car don't start.. someone said it was to do with the engine.....
;)

Regards,

Ian
[1]: Redirecting using: '/somepage.php' is wrong accordin to the HTTP
RFC IIRC.. this is required to be a complete URL:
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/somepage.php'
);
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPwKsemfqtj251CDhEQIIfQCdFd58HyPWpO0Fx/U0RmH1lCys67kAn34P
lxHSN851joEmuSYBK0JipWEG
=lOWm
-----END PGP SIGNATURE-----

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2

P: n/a
Also I should add the actual error was

Parse error: parse error, unexpected T_IS_EQUAL, expecting ',' or ')'
in c:\inetpub\wwwroot\cms\class\createPage.php on line 23
ma**@presspley.com (presspley) wrote in message news:<7a**************************@posting.google. com>...
I have bought the book on advanced dreamweaver and PHP recently. I
have installed MySQL and PHP server but am getting an error on the
$GET statement show below. It says there is a problem with the
variable $GET but $GET is not a variable, I thought it came from the
page that calls the PHP file?

if(($_GET['type'])==""){

this gets an error
<?php
require_once("class/displayNews.php");
require_once("class/displayArticle.php");
require_once("class/displayMenu.php");
################################################## ##
# CMS Page Class #
################################################## ##

class Page{

var $type;
var $mainContent;
var $pageTitle;
var $menu;

function Page(){
$this->getType();
$this->createMenu();
}

function getType(){
if(isset($_GET['type'])){
if(($_GET['type'])==""){
$link = $PHP_SELF . "?type=article&menuID=0";
header("Location:" . $link);
}
if($_GET['type']=="news"){
$this->news();
}
if($_GET['type']=="article"){
$this->article();
}
}
}

Jul 16 '05 #3

P: n/a
ma**@presspley.com (presspley) wrote in message news:<7a**************************@posting.google. com>...
I have bought the book on advanced dreamweaver and PHP recently. I
have installed MySQL and PHP server but am getting an error on the
$GET statement show below. It says there is a problem with the
variable $GET but $GET is not a variable, I thought it came from the
page that calls the PHP file?

if(($_GET['type'])==""){


I could only suggest it's the extra ( ) around the variable that's
causing the problem, although it works fine on PHP 4.3.2.

However, the whole function isn't well written, IMO. If you have more
than two statement blocks executed by IF, you should use switch
instead. As Ian.H pointed out relative redirects are not RFC compliant
and only work if the browser allows it. They also drop in and out of "
to build strings. You don't need to do that. PHP will swap variable
names in strings very happily and if you enclose array variables in {
} it will work with them too. I'd write the routine like this.

function getType() {
if (isset($_GET['type'])) {
switch ($_GET['type']) {
case "" :
$link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?type=article&menuID=0";
header ("Location: $link");
break;
case "news" :
$this->news();
break;
case "article" :
$this->article();
}
}
}
Jul 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.