Page 1 of 1

problem in php 5.0.5 !!!!

Posted: Tue Jan 03, 2006 6:01 am
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");
?>

Posted: Tue Jan 03, 2006 6:57 am
by twigletmac
Do you get any error messages?

Mac

No error mesage

Posted: Tue Jan 03, 2006 7:01 am
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

Posted: Tue Jan 03, 2006 7:07 am
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

Posted: Tue Jan 03, 2006 7:15 am
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

Posted: Tue Jan 03, 2006 7:26 am
by twigletmac
Did you change the $page in the if statement to $_GET['page'] too?

Mac

Posted: Tue Jan 03, 2006 7:33 am
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

Posted: Tue Jan 03, 2006 7:46 am
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

again problem :(

Posted: Mon Jan 09, 2006 10:57 am
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

Posted: Mon Jan 09, 2006 11:21 am
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.

Posted: Mon Jan 09, 2006 11:35 am
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

Posted: Mon Jan 09, 2006 11:53 am
by twigletmac
You need to test against $_GET['page'] (as before) instead of just $_GET

Mac

Posted: Mon Jan 09, 2006 12:11 pm
by roobik
twigletmac wrote:You need to test against $_GET['page'] (as before) instead of just $_GET

Mac
Thanks ! it worked normaly !