Php Is Not Working???

Status
Not open for further replies.

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
: having problems
i cannot navigate in my site the same way
The When i Click on the links most of them take me to the same page i used php and now i thing there is some thing wrong with the php in the Server.
example:
http://dharmil.x10hosting.com/index.php?x=home
http://dharmil.x10hosting.com/index.php?x=portfolio
http://dharmil.x10hosting.com/index.php?x=contact
http://dharmil.x10hosting.com/index.php?x=links
All of them go to the same page.
When i Checked My files There was nothing wrong with the code it was the same i have all the pages i had before.

Also One Of my two subdomain is not working
http://www.mp3.dharmil.x10hosting.com/index.php (Works)
http://www.forums.dharmil.x10hosting.com/index.php (Does not work)
But in my cpanel They both show up
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
You prolly made use of register_globals being turned on. I was just posting in another thread about this.

To fix the problem, go into your scripts and see if you have something like:

if ($home) {
include('homepageblah.php');
elseif ($contact) {
include('contactpageblah.php');
elseif ($links) {
include('linkspageblah.php');
} etc etc.

To fix it, you need to change the: if ($page) { part to use the $_GET superglobal array. Each name=value pair in the URL is placed into this array, like this:

-Say you go to index.php?page=home. In your PHP scripts, $_GET['page'] is now set to "home". (So you would use if ($_GET['page'] == "home") { )
-Say you go to index.php?page=links. In your PHP scripts, $_GET['page'] is now set to "links". (So you would use if ($_GET['page'] == "links") { )

I just assuming this is how you have it set up.

Register globals is a security risk, and that is why it was turned off by default in PHP 4.2.0+

If you have *no clue* wth I'm talking about, then.. *sigh* post back and ask away. Also check out: http://us2.php.net/manual/en/security.globals.php
 
Last edited:

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
I did this
<?php
if ($x == "") $x = "home";
include ("pages/$x.php");
?>

well thanks for trying
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
PHP:
<?php
if ($_GET['page']) { $page = "home"; } else { $page = $_GET['page']; }
include ("pages/$page.php");
?>
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
Warning: main(pages/.php): failed to open stream: No such file or directory in /home/dharmilx/public_html/index.php on line 157

Warning: main(): Failed opening 'pages/.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dharmilx/public_html/index.php on line 157
what?
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
PHP:
<?php
if ($_GET['x']) { $page = "home"; } else { $page = $_GET['page']; }
include ("pages/$page.php");
?>

Do you know PHP at all? I had 'page.php?page=home' etc etc instead of 'page.php?x=home' etc etc. Sorry..
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
look this is the problem

Warning: main(pages/.php): failed to open stream: No such file or directory in /home/dharmilx/public_html/index.php on line 158

Warning: main(): Failed opening 'pages/.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dharmilx/public_html/index.php on line 158

i dont know how to explain but just go to
http://dharmil.x10hosting.com/index.php
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
I just whould like to what the error means cuz it says missing file and its all there I read the thing but it dosent explain the error
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
These errors?
PHP:
Warning: main(pages/.php): failed to open stream: No such file or directory in /home/dharmilx/public_html/index.php on line 158

Warning: main(): Failed opening 'pages/.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dharmilx/public_html/index.php on line 158

The first error there is caused by the include construct trying to "include" (Obviously :) the file pages/.php.

The second error with the main(): part is caused because PHP will try to load the file pages/.php from the include_path. (Which I believe is set in php.ini.. )

Anyways, neither of these files exist, so thus you get the error about the inclusion of it failing.

The entire error though is caused by the include construct trying to do
PHP:
..
include($_GET['page'] .".php");
..

Since $_GET['page'] was not being set, ($_GET['x'] was instead by the way), nothing gets put before the ".php", so ".php" is attempted to be included.

I hope I cleared that up for you. :)
 

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
Thanks
I understand but How do i fix it
I am sorry for bothering you.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
No it's fine haha.

Ahh I see the problem. I am sorry, I didn't see that you posted those errors, so I thought you were talking about the older ones.

To fix it, add something such as:

PHP:
<?php
  if (!$_GET['x']) {
      $page = "home";
   } else {
      $page = $_GET['x'];
   }

   include ($page .".php");
?>

Uhh yea. I messed up with my other "helping post". I'm sorry. Anyways, that should work. It is a potential security risk, but nothing really all that harmful could come of it.

Edit: You could even try this..

PHP:
<?php

$page = $_GET['x'];

  if (!$page) {
      $page = "home";
   } else {
      $page = str_replace(":", "", $page);
      $page = str_replace( "/", "", $page);
      $page = str_replace( ".", "", $page);
      $page = str_replace( "http", "", $page);
      $page = str_replace( "www", "", $page);
   }

   include ($page .".php");
?>
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Haha your welcome. I was checking out your site a few minutes before you posted and noticed that the error was gone. :)

If you ever need any more help, just ask..
 

NielsJanssen

New Member
Messages
148
Reaction score
0
Points
0
is the file actualle named 'pages/.php'??
cauze that might be the error
it tries to find the 'pages/.php' file but it can't find it
try changing the 'pages/.php' to 'pages.php'
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
He had/has the pages in a the directory pages/, so when he tried to open pages/'. $_GET['page'] .'.php, $_GET['page'] wasn't set, so the script actually would try to open pages/.php, which would result in an error.

Woo, that was a mouthful to say.
 
Status
Not open for further replies.
Top