PDA

View Full Version : URL filtering varables



fileserverdirect
11-07-2007, 10:21 PM
Hello,
I am going to get straight to the point without explaining my life story(site story) and problems(as I am known for).
How do you strip a url from its ?a-var=b-value&d-var=c-value I have used: $_SERVER['PHP_SELF'], but that returns all the passed on varables. Can someone show me a simple script for this. Thanks,
FSD.

Fixed formatting.

Twey
11-07-2007, 10:50 PM
I'm not sure what you mean.
$url = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?'));

fileserverdirect
11-07-2007, 11:27 PM
It worked, but I had to add $_SERVER['SERVER_NAME'] so that the full url showed up. I am having second thoughts about this. The whole point was to just add ?skip=yes to the url. This is for the Validator. When the script sees that skip=yes it skips the whole cookie setting page, which is not the actual page being validated. So why just not add &skip=yes to the end? well W3's validator does not like it, it wants you to "encode" it to & It gave a link to a page because sooo many of these perfictly valid pages were getting turned down, and it said to change the seaporator in URL's!?!? There has got to be an eaiser way, plus I cannot change the php.ini file to even make the change.
And sometimes its a completly different page without the passed on varible. HELP!

Twey
11-08-2007, 01:35 AM
It worked, but I had to add $_SERVER['SERVER_NAME'] so that the full url showed up.Whoops, yes, missed that.
The whole point was to just add ?skip=yes to the url. This is for the Validator. When the script sees that skip=yes it skips the whole cookie setting page, which is not the actual page being validated.Why not just set the cookies on the actual page?
So why just not add &skip=yes to the end? well W3's validator does not like it, it wants you to "encode" it to & It gave a link to a page because sooo many of these perfictly valid pages were getting turned down, and it said to change the seaporator in URL's!?!? There has got to be an eaiser way, plus I cannot change the php.ini file to even make the change.You misunderstood it. Often, site authors have a link like this:
<a href="somepage.php?a=1&b=2">Click!</a>This is not valid HTML, because the & symbol indicates the start of an entity reference like &nbsp; or &aumlaut;. Instead, you're meant to escape the & symbol:
<a href="somepage.php?a=1&amp;b=2">Click!</a>This results in the same URL, but is safely embedded in the HTML. Because this can be a bit of a hassle, the W3C recommends that scripts use the semicolon character instead, which is perfectly valid according to the CGI specification:
<a href="somepage.php?a=1;b=2">Click!</a>Unfortunately, PHP is notoriously lax about following this specification, and doesn't support it by default: you have to enable it in php.ini or parse the query string yourself. The easiest solution is probably just to use &amp;.

fileserverdirect
11-08-2007, 08:42 PM
Code:
<a href="somepage.php?a=1&amp;b=2">Click!</a>This results in the same URL, but is safely embedded in the HTML. Because this can be a bit of a hassle, the W3C recommends that scripts use the semicolon character instead, which is perfectly valid according to the CGI specification
1.So what your saying is that I can use &amp; and It wont Effect the code? If so, I have already started to write a function called url("the.url.com", "to return value or make a link", "any attributes to add to the <a> tag"); and now I will add "to encode or not" which would use what function? Is it like htmlspecialchars() or somthing? Maybe I can use the hex value or somthing(or whatever the name is for %20 being "space").
2."Because this can be a bit of a hassle..."
Not at all, with my url encoder.

Why not just set the cookies on the actual page?
2 words:
L O N G S T O R Y
The topic that I posted for that issue was well over 20 posts total :)

Twey
11-09-2007, 12:33 AM
htmlspecialchars() will do just fine.
Maybe I can use the hex value or somthing(or whatever the name is for %20 being "space").That's URL encoding, and isn't what you want to do here. You need to escape & for use in HTML, but URL encoding is a form of encoding targetted at the HTTP protocol.

fileserverdirect
11-10-2007, 12:18 PM
A bit of a problem...
But first, the &amp; worked, the page is valid! But wait, it's not validating &skip in the url. It thinks that the amperstand is part of W3's url!!! Not mine! I have even tried &amp;amp; in the url, but it still does not work! Help.

Twey
11-10-2007, 05:38 PM
What are you talking about? :-\ I'll need to see the offending link.

fileserverdirect
11-10-2007, 07:53 PM
I guess I was a little vauge,

What I am trying to say is that It thinks that the amperstand in my url, that's being submitted, is being translated to being part of W3's url. For example:

http://validator.w3.org/check?uri=www.mysite.com/tests/whatever/index.php?w=1056&skip=yes
The validator is taking skip=yes and putting it part of it's own url, so it's only validating:

http://validator.w3.org/check?uri=www.mysite.com/tests/whatever/index.php?w=1056
and thinking &skip=yes is for the validator! I have tried the following, and it ethier did not work at all, or validated a differant page because of it:


&amp;ampskip=yes
%26amp;skip=yes
%26skip=yes
%2526skip=yes
&amp;skip=yes
%26amp;amp;skip=yes
%2526amp;amp;skip=yes

I hope you understand now what the problem is.
Thanks,

Twey
11-10-2007, 07:57 PM
There you do need to URL-encode it:
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.mysite.com%2Ftests%2Fwhatever%2Findex.php%3Fw%3D1056%26skip%3Dyes

fileserverdirect
11-10-2007, 08:03 PM
Is there a php function for that?
EDIT: nvm, new problem, I used urlencode();, it works, but when it validates, It takes everything out, and translates it. They probally use urldecode(); before validating.