[php] show url on page

  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

Hello
I want to add a function do my site. That shows you a link to the site you are on.
Code: [ Select ]
domain.com/details.php?image_id=9930&sessionid=b300aa2b0d65d9162e91db57190a5848

But I want it without the sessionid. Is that possibly?

- lars
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

PHP Code: [ Select ]
$str = "domain.com/details.php?image_id=9930&sessionid=b300aa2b0d65d9162e91db57190a5848";
 
echo explode($str, "?")[0];
  1. $str = "domain.com/details.php?image_id=9930&sessionid=b300aa2b0d65d9162e91db57190a5848";
  2.  
  3. echo explode($str, "?")[0];


Not tested, but should split up the string based on the "?" character, and return the first item in the array, i.e., the "domain.com/details.php" part.
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

can' t seem to get it to work.
Isn't there a way to use
Code: [ Select ]
http://{$HTTP_HOST}{$REQUEST_URI}

And but a limit, so it only shows to image_is=xxx ?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2391
  • Loc: Edinburgh, Scotland

Post 3+ Months Ago

Ok, say you've got your URL : http://www.ozzu.com/posting.php?mode=reply&t=39640

To return this string upt to the end of the mode=reply bit, use the following:
PHP Code: [ Select ]
$str = $_SERVER["HTTP_HOST"].$_SERVER["PATH_INFO"];
 
$posAmp = strpos($str, "&");
 
echo substr(0, $posAmp);
  1. $str = $_SERVER["HTTP_HOST"].$_SERVER["PATH_INFO"];
  2.  
  3. $posAmp = strpos($str, "&");
  4.  
  5. echo substr(0, $posAmp);


Again, it's not tested (don't have PHP installed on my machine at work).
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

That doesn't do anything :(
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1615

Post 3+ Months Ago

Here you go. This should work - I tested it quickly there. This will post the URL regardles of whether sessionid is in the URL or not, and will remove sessionid prefixed by &,? or anything else.

Code: [ Select ]
$str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$sid = strpos($str, "sessionid")-1;
if ($sid > 0) { echo substr($str,0,$sid);}
else {echo $str;}
  1. $str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
  2. $sid = strpos($str, "sessionid")-1;
  3. if ($sid > 0) { echo substr($str,0,$sid);}
  4. else {echo $str;}
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Well its a little more code then the rest, but I know it works.
PHP Code: [ Select ]
<?php
 
$url = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
 
$i = 0;
 
foreach($_GET as $k=>$v) {
 
   $url .= $k . "=" . $v;
 
   if($i < count($_GET)-1)
 
      $url .= "&";
 
   $i++;
 
}
 
echo "<br>" . $url;
 
?>
  1. <?php
  2.  
  3. $url = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
  4.  
  5. $i = 0;
  6.  
  7. foreach($_GET as $k=>$v) {
  8.  
  9.    $url .= $k . "=" . $v;
  10.  
  11.    if($i < count($_GET)-1)
  12.  
  13.       $url .= "&";
  14.  
  15.    $i++;
  16.  
  17. }
  18.  
  19. echo "<br>" . $url;
  20.  
  21. ?>
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

lionking wrote:
Here you go. This should work - I tested it quickly there. This will post the URL regardles of whether sessionid is in the URL or not, and will remove sessionid prefixed by &,? or anything else.

Code: [ Select ]
$str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$sid = strpos($str, "sessionid")-1;
if ($sid > 0) { echo substr($str,0,$sid);}
else {echo $str;}
  1. $str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
  2. $sid = strpos($str, "sessionid")-1;
  3. if ($sid > 0) { echo substr($str,0,$sid);}
  4. else {echo $str;}


That works :D
Is there a way to add http// (href) So it works as a link? :wink:
  • lioness
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1615

Post 3+ Months Ago

BartAfterDark wrote:
lionking wrote:
Here you go. This should work - I tested it quickly there. This will post the URL regardles of whether sessionid is in the URL or not, and will remove sessionid prefixed by &,? or anything else.

Code: [ Select ]
$str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$sid = strpos($str, "sessionid")-1;
if ($sid > 0) { echo substr($str,0,$sid);}
else {echo $str;}
  1. $str = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
  2. $sid = strpos($str, "sessionid")-1;
  3. if ($sid > 0) { echo substr($str,0,$sid);}
  4. else {echo $str;}


That works :D
Is there a way to add http// (href) So it works as a link? :wink:


Try changing the first line to this...
Code: [ Select ]
$str = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];

If that doesn't work remove the quotes around http://
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

still not working fully.
Is there a way so it is like a real link?
  • darkermoon
  • Expert
  • Expert
  • User avatar
  • Posts: 542
  • Loc: Riverdale, MD

Post 3+ Months Ago

well, you still have to make the actual link.. you know, <a href=...>text</a>

that's kind of obvious.. but I think it's what you're asking for.

just use an echo to output it.

PHP Code: [ Select ]
echo <a href=\"$str\">$str</a>
I'm pretty sure that should work but, it doesn't look quite right.. I'm really tired today.
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

darkermoon that code doesn't work :'(
  • SSH-Raj
  • Expert
  • Expert
  • User avatar
  • Posts: 588

Post 3+ Months Ago

Code: [ Select ]
<?php echo '<a href="'.$str.'">'.$str.'</a>'; ?>
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Try:
PHP Code: [ Select ]
<?php
 
$url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
 
$i = 0;
 
foreach($_GET as $k=>$v) {
 
    $url .= $k . "=" . $v;
 
    if($i < count($_GET)-1)
 
        $url .= "&";
 
    $i++;
 
}
 
echo "<a href=\"http://" . $url . "\">" . $url . "</a>";
 
?>
  1. <?php
  2.  
  3. $url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
  4.  
  5. $i = 0;
  6.  
  7. foreach($_GET as $k=>$v) {
  8.  
  9.     $url .= $k . "=" . $v;
  10.  
  11.     if($i < count($_GET)-1)
  12.  
  13.         $url .= "&";
  14.  
  15.     $i++;
  16.  
  17. }
  18.  
  19. echo "<a href=\"http://" . $url . "\">" . $url . "</a>";
  20.  
  21. ?>
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

doesn't do the trick :( Getting parse errors :'(
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

http://sc0rp.ath.cx/test/get.php?id=a;l ... test5=asdf
That is this script exactly.
PHP Code: [ Select ]
<?php
 
$url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
 
$i = 0;
 
foreach($_GET as $k=>$v) {
 
    $url .= $k . "=" . $v;
 
    if($i < count($_GET)-1)
 
        $url .= "&";
 
    $i++;
 
}
 
echo "<a href=\"http://" . $url . "\">http://" . $url . "</a>";
 
?>
  1. <?php
  2.  
  3. $url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
  4.  
  5. $i = 0;
  6.  
  7. foreach($_GET as $k=>$v) {
  8.  
  9.     $url .= $k . "=" . $v;
  10.  
  11.     if($i < count($_GET)-1)
  12.  
  13.         $url .= "&";
  14.  
  15.     $i++;
  16.  
  17. }
  18.  
  19. echo "<a href=\"http://" . $url . "\">http://" . $url . "</a>";
  20.  
  21. ?>
  • BartAfterDark
  • Graduate
  • Graduate
  • BartAfterDark
  • Posts: 120

Post 3+ Months Ago

Scorpius wrote:
http://sc0rp.ath.cx/test/get.php?id=a;lfkj&test=adf;&test5=asdf
That is this script exactly.
PHP Code: [ Select ]
<?php
$url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
$i = 0;
foreach($_GET as $k=>$v) {
    $url .= $k . "=" . $v;
    if($i < count($_GET)-1)
        $url .= "&";
    $i++;
}
echo "<a href="http://" . $url . "">http://" . $url . "</a>";
?>
  1. <?php
  2. $url = $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF] . "?";
  3. $i = 0;
  4. foreach($_GET as $k=>$v) {
  5.     $url .= $k . "=" . $v;
  6.     if($i < count($_GET)-1)
  7.         $url .= "&";
  8.     $i++;
  9. }
  10. echo "<a href="http://" . $url . "">http://" . $url . "</a>";
  11. ?>


I love you :D :D :D
  • darkermoon
  • Expert
  • Expert
  • User avatar
  • Posts: 542
  • Loc: Riverdale, MD

Post 3+ Months Ago

I could do this but, it's always really late at night when I'm on here and my brain's fried from hours of PHP. What I think would be good for you is to learn PHP so you know what the script actually does and understand how code is written rather than solely depending on people to do it for you.

//EDIT: see your problem is resolved. congrats.
  • Jacob Marshall
  • Born
  • Born
  • Jacob Marshall
  • Posts: 2

Post 3+ Months Ago

Code: [ Select ]
<?php
$url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
echo "<a href='$url'>$url</a>";
?>
  1. <?php
  2. $url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
  3. echo "<a href='$url'>$url</a>";
  4. ?>


That works!

Post Information

  • Total Posts in this topic: 19 posts
  • Users browsing this forum: No registered users and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.