problem in php 5.0.5 !!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

problem in php 5.0.5 !!!!

Post by roobik »

Hi !
I'm beginner in php ! I have a code for showing my web sites pages in index.php file now I put this code to new web site but it dosn't work !!!!!
Can any one hlp me what is the problem ?!

Code: Select all

<?if (file_exists("files/".$page.".php"))	  	
include ("files/".$page.".php");
else include ("files/default.php");
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get any error messages?

Mac
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

No error mesage

Post by roobik »

I onle see the default.php !!!!!!!
when i click in other linkes " include ("files/".$page.".php"); " dont work !!!!!!
twigletmac wrote:Do you get any error messages?

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I guess that the page variable is being passed in the URL - i.e. something like http://www.yoursite.com/content.php?page=test ?

If so then you will need to change $page to $_GET['page'].

Mac
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Post by roobik »

Like this ?

include ("files/"$_GET".php");

I try this but dont work again !!!! :(
twigletmac wrote:I guess that the page variable is being passed in the URL - i.e. something like http://www.yoursite.com/content.php?page=test ?

If so then you will need to change $page to $_GET['page'].

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you change the $page in the if statement to $_GET['page'] too?

Mac
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Post by roobik »

Thanks a lot now it work :)))

Why the same worked in other hosting normaly ?!
twigletmac wrote:Did you change the $page in the if statement to $_GET['page'] too?

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's because register_globals has been turned off on the new server. You will probably need to rewrite a lot of code if you've been depending on it being turned on but this is a good thing as it will make your code much easier to move between servers.

http://php.net/register_globals

Mac
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

again problem :(

Post by roobik »

Hi !
May this code have the same problem ?!

Code: Select all

if($page=='default'){
	print 'Web hosting, domain names and web design services by HostingMarkets ';
}
elseif($page=='About'){
	print 'About HostingMarkets web hosting Company';
}
else{
	print 'Web hosting, domain names and web design services by HostingMarkets';
}
twigletmac wrote:It's because register_globals has been turned off on the new server. You will probably need to rewrite a lot of code if you've been depending on it being turned on but this is a good thing as it will make your code much easier to move between servers.

http://php.net/register_globals

Mac
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Yep.

Any variables being passed via the url should use $_GET. Any being passed via POST (e.g. a form using the POST method - which it should always use) should be referenced from $_POST.

Doing things this way gives you a better idea of where variables are coming from, and as stated already it ensures your code will work on nearly any PHP server (assuming its PHP5 safe also - not that hard ;)).

You should read up on using the GET and POST superglobals in the PHP manual. Give a good idea how they work, and why they are better.
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Post by roobik »

Maugrim_The_Reaper wrote:Yep.

Any variables being passed via the url should use $_GET. Any being passed via POST (e.g. a form using the POST method - which it should always use) should be referenced from $_POST.

Doing things this way gives you a better idea of where variables are coming from, and as stated already it ensures your code will work on nearly any PHP server (assuming its PHP5 safe also - not that hard ;)).

You should read up on using the GET and POST superglobals in the PHP manual. Give a good idea how they work, and why they are better.
I use this code for my site titel !!!
For example !

Code: Select all

<title><?
if($_GET=='default'){
	print 'Web hosting, domain names and web design services by HostingMarkets ';
}
elseif($_GET=='About'){
	print 'About HostingMarkets web hosting Company';
}
elseif($page=='plans'){
	print 'HostingMarkets - Web Hosting Plans';
}
elseif($page=='reseler'){
	print 'Web Hosting, Reseller Hosting, Hosting Markets';
}
elseif($page=='legal'){
	print 'HostingMarkets Legal Information';
}
elseif($page=='support'){
	print 'Technical Support for HostingMArkets Web Hosting';
}
elseif($page=='contact'){
	print 'Contact HostingMarkets for all Your Web Hosting Needs';
}
else{
	print 'Web hosting, domain names and web design services by HostingMarkets';
}
?></title>
but i dont work when I see " http://www.mysite.com/index.php?page=about " in my site URL
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need to test against $_GET['page'] (as before) instead of just $_GET

Mac
roobik
Forum Newbie
Posts: 10
Joined: Tue Dec 27, 2005 3:15 am

Post by roobik »

twigletmac wrote:You need to test against $_GET['page'] (as before) instead of just $_GET

Mac
Thanks ! it worked normaly !
Post Reply