Jump to content


Photo

Quirk when adding a slash '/' after page.php


  • Please log in to reply
20 replies to this topic

#1 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 09:11 AM

I discovered a strange quirk with my site. If I add a slash after a script name, such as index.php/, then my page will show up but with no formating or style sheet, just a white page with text.

Does anyone know why this happens? What might be a way to prevent this?

#2 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 10 July 2006 - 09:23 AM

Yeah dont put a slash at the end

#3 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 10:16 AM

It's not me I'm worried about. It's my visitors. I wouldn't want anyone to see my site like that, without images or style sheets applied. There must be a way to solve this problem.

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 July 2006 - 10:52 AM

Show more code why are you applying a slash to the end index.php/
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 08:53 PM

I'm not applying a slash after index.php file, but if I do, I get the error. Sometimes people play around with URLs and i don't want my site to show up as text only if someone messes with the URL.

#6 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 09:01 PM

I think that it may be that when you put a slash the server looks for the folder /page.php/
which doesn't exist.
So, it returns the 404 page which is your page except that the browser thinks the page URL is /page.php/page.php which means that the URLs of the images/styles will be incorrect.

My conclusion is that your 404 page should redirect to the main page which will display correctly.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#7 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 10 July 2006 - 09:02 PM

seems a little pointless, but:

<?php
$self = $_SERVER["PHP_SELF"];
if (eregi('/$',$self)){
$newurl = explode("/",$self);
$newurl = $newurl[1];
header("location:$newurl");
}
?>


#8 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 09:18 PM

Shogun, I think you are partly correct. It is probably looking for the page.php directory. But it's not returning a 404 error, but instead it's processing the script and outputting the html content, minus images and style.

GingerRobot, I think you have a good idea, but it's not practical, because then anytime I had a slash in the url, it's going to redirect. Sometimes there might be a need for a trailing slash. I'll write up something custom to solve this I guess. I was just checking to find out if this is a common issue and if there was a common solution.

#9 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 10 July 2006 - 09:21 PM

That will only redirect if the forward slash is at the end of the file.

#10 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 10 July 2006 - 09:26 PM

its probably messing up where your style sheet is located or pics are located because you put the slash on the end? like i know sometimes when you go to a directory that has a index.htm in it it will automaticly go to that page! I.E www.example.com/main
"Syntax error" .. WHERE THE **** IS IT?!

#11 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 09:35 PM

GingerRobot had something going there, I tested this:
<?php
$self = $_SERVER["PHP_SELF"];
if (eregi('/$',$self)){
$newurl = explode("/",$self);
$newurl = $_SERVER['SCRIPT_NAME'];
header("Location:$newurl");
}
?>
[/code[
When I used it like so: [b]http://www.domain.com/index.php/[/b] it will redirect to [b]http://www.domain.com/index.php[/b]

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#12 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 10 July 2006 - 09:45 PM

Just realised, that wouldn't work if the file was in a sub directory, but this would:

<?php
$self = $_SERVER["PHP_SELF"];
if (eregi('/$',$self)){
$newurl = explode("/",$self);
foreach($newurl as $newurl){
  if(eregi('[[:alnum:]]\.[[:alnum:]]',$newurl)){
    $url = $newurl;
    break;
}
}
header("location:$url");
}
?>


#13 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 09:49 PM

That will only redirect if the forward slash is at the end of the file.


I realise that, but what if the url looks like:

mydomain.com/category1/category2/

I didn't test it, but my guess is that your code wouldn't work here.

-----

Note, I wrote this before Ginger's last post. I don't know how your new code would affect this.

One solution might be to test the REQUEST_URI for a '.ext/' case and then if found, strip the slash, or just strip everything after the .ext if one doesn't plan on allowing that condition.

#14 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 10 July 2006 - 09:51 PM

That will only redirect if the forward slash is at the end of the file.


well given that the code would have to be placed in a file, so the url would have to be something like mydomain.com/category1/category2/file.php /

the updated code would work.
I realise that, but what if the url looks like:

mydomain.com/category1/category2/

I didn't test it, but my guess is that your code wouldn't work here.



#15 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 10 July 2006 - 09:57 PM

Well I imagine that the 404 should kick in there, not a place for PHP.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#16 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 10 July 2006 - 09:59 PM

This is all does seem kind of pointless though, i mean, if someone wants to go fiddling with the url what do they expect?

#17 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 10:20 PM

This is all does seem kind of pointless though, i mean, if someone wants to go fiddling with the url what do they expect?


Well, perhaps you are right. But it bugs me and it just seems like a flaw. If it is fixable, then why not fix it?

#18 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 10 July 2006 - 11:16 PM

Ok, here's my code!

$uri = $_SERVER['REQUEST_URI'];

$slashcheck = "\.{1}[a-zA-Z]{3}/+";
$extcheck = "\.{1}[a-zA-Z]{3}";

if (eregi($slashcheck, $uri)){
    //echo "slashfound<br />";
    $newurl = '/';
    $uri = explode('/', $uri);		  
		$count = count($uri);
		$x = 0;
		$end = 0;		
  		foreach($uri AS $value){
  		  $x++;
  		  if(!eregi($extcheck, $value) && $value !='' && $end != 1){
  		    $newurl .= $value.'/';
  		    //echo $value." Has has no ext.<br />";
  		  }
  		  if(eregi($extcheck, $value) && $end != 1){
  		      //echo $value." Has an .ext<br />"; 		    
  		      $newurl .= $value;
  		      
  		      $end = 1;
  		  } 				
  		}//end foreach
  	echo $newurl."<br />";
}

//then of course course redirect to new location...

As an example,

$uri = 'index1.php/index2/index3.php/';
returns:
index1.php

$uri = 'index1php/index2/index3.php/';
returns:
index1php/index2/index3.php

$uri = 'index1php/index2.php/////index3.php/';
returns:
index1php/index2.php

#19 mmosel

mmosel
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 11 July 2006 - 09:02 PM

Another tip that I received on another board I visit is a very simple and elegant solution. It doesn't require any special code. Just use the base tag:

<base href="http://mydomain.com/" />

And then all of your relative links will magically work as if they were absolute links!
Such a simple thing, but it works like a charm. Works for .css, images, and more.



#20 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 11 July 2006 - 11:30 PM

Except in some browsers ;)
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users