Page 1 of 1

Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 10:05 am
by simonmlewis

Code: Select all

function curPageURL() 
{
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
$url = curPageURL();
This is meant to grab all the URL from the page.
The problem I've got is that in the URL that I am grabbing, there will be & signs.

Furthermore, I am posting the grabbed URL and placing it on the end of the current URL. The purpose is to use a text link to post the URL to a form, while keeping the contents of the page, within the page.

So the result with the grabbed URL is something like this:

http://www.thisismydomain.com/index.php ... d1=4&id2=3.

I've only just realised that it won't post half of the URL to the next page because there are & signs..... so it post:

$url = http://www.thisismydomain.com/index.php?page=home

Is there a method around this - apart from using a <form> tag instead?

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 10:07 am
by AbraCadaver
urlencode() the grabbed url.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 10:28 am
by simonmlewis
I've done that, but I am assuming I am meant to be seeing the & signs turned into something else - but nothing changes.

Also, with that posting via the URL to the next page, do I just extract it via the $url=$_REQUEST['url'];, and insert it into the 'send friend' form via $url?

I ask all this, because it still only goes up to the first &.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 10:49 am
by AbraCadaver
simonmlewis wrote:I've done that, but I am assuming I am meant to be seeing the & signs turned into something else - but nothing changes.

Also, with that posting via the URL to the next page, do I just extract it via the $url=$_REQUEST['url'];, and insert it into the 'send friend' form via $url?

I ask all this, because it still only goes up to the first &.
I don't know what you're doing, but:

Code: Select all

echo 'http://www.thisismydomain.com/index.php?page=home&id1=4&id2=3&url=' . urlencode('http://www.thisismydomain.com/index.php?page=home&id1=4&id2=3');
Gives:
[text]http://www.thisismydomain.com/index.php ... %26id2%3D3[/text]
This will work fine.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 10:57 am
by simonmlewis

Code: Select all

function curPageURL() 
{
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
$url = curPageURL();
<a href=\"index.php?page=selectorsend&menu=home&bid=$bid&brc=$brc&id1=$id1&id2=$id2&id3=$id3&id4=$id4&id5=$id5&id6=$id6&id7=$id7&id8=$id8&id9=$id9&id10=$id10&id11=$id11&id12=$id12&id13=$id13&id14=$id&url=" . urlencode($url). "\" style='text-decoration: none'><img src='images/btn_sendfriend.png' border='0' /></a>
Does this:
[text]<a href='index.php?page=selectorsend&menu=home&id1=10&id2=109&id3=76&id4=70&id5=&url=http://localhost/phpmyadmin/justbbguns/ ... n&finish=y' style='text-decoration: none'><img src='images/btn_sendfriend.png' border='0' /></a>
[/text]

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 11:42 am
by AbraCadaver
That link is not valid HTML or PHP.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 11:49 am
by simonmlewis
May I ask why not?
I have forgotten to show the echo ""; part in the code, but apart from that it looks ok.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 11:55 am
by AbraCadaver
simonmlewis wrote:May I ask why not?
I have forgotten to show the echo ""; part in the code, but apart from that it looks ok.
Yeah the echo ""; part makes a difference. Aside from that though, I can't see a problem. I have no idea why you're not getting the correct output. It must be something else (not updating the file when you make changes, working on the wrong code, etc...)

It's odd that in your echo you use double quotes around the href, but the output that you show has single quotes :wink: That's not the output from that code.

Re: Why does this curPageURL(); not work?

Posted: Wed Jul 07, 2010 12:51 pm
by simonmlewis
Bingo. I turned it all around. echo ' instead of echo ", so there was no need for \" around the Javascript.

All fine now. Thanks very much.

Re: Why does this curPageURL(); not work?

Posted: Thu Jul 08, 2010 5:47 am
by simonmlewis

Code: Select all

echo '<div style="float: right; text-align: right; width: 305px; margin-right: 10px">
<a href="index.php?page=selectorsend&menu=home&id1=$id1&id2=$id2&id3=$id3&id4=$id4&id5=$id5&url=' . urlencode($url) . '" style="text-decoration: none"><img src="images/btn_sendfriend.png" border="0" /></a>
<a href="javascript:history.back()"><img src="images/btn_remove.png" border="0" /></a>
<a href="index.php?page=selector&menu=home" style="text-decoration: none"><img src="images/btn_restart.png" border="0" /></a>
<br/>Send this to yourself or your friends to review.<br/>Then you or they can come back and make the purchase.</div>';
PROBLEM:
All this now renders is id1=$id1 in the URL, not the dynamic id1=311 (for example).

The 'id's are all REQUESTED at the top of the page. Is it something to do with my ' and " usage??

Re: Why does this curPageURL(); not work?

Posted: Thu Jul 08, 2010 5:59 am
by simonmlewis
Plan B - and this does work.

Code: Select all

$newurl = urlencode($url);

echo "<div style='float: right; text-align: right; width: 305px; margin-right: 10px'>
<a href='index.php?page=selectorsend&menu=home&id1=$id1&id2=$id2&id3=$id3&id4=$id4&id5=$id5&url=$newurl' style='text-decoration: none'><img src='images/btn_sendfriend.png' border='0' /></a>
<a href=\"javascript:history.back()\"><img src='images/btn_remove.png' border='0' /></a>
<a href='index.php?page=selector&menu=home' style='text-decoration: none'><img src='images/btn_restart.png' border='0' /></a>
<br/>Send this to yourself or your friends to review.<br/>Then you or they can come back and make the purchase.</div>";