Jump to content


QUERY_STRING ?


6 replies to this topic

#1 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 05 December 2006 - 11:14 AM

Hello!

Can i fetch only short part of url whit $_SERVER["QUERY_STRING"] thing?

example my url is

http://www.mysite.com/index.php?id=7&case=254&mode=autorun

i need to get only this part of that url somehow:

http://www.mysite.com/index.php?id=7

could it be done whit QUERY_STRING thing or somehow else?

in my script i got this:

$juuri = $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];

that fetch only this
http://www.mysite.com/index.php

Okey, thanks for all help! :D

#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 05 December 2006 - 12:19 PM

Try this

<?php
$url = explode('&', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
echo $url[0];
?>


#3 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 05 December 2006 - 12:36 PM

View PostAv-, on Dec 5 2006, 05:19 PM, said:

Try this

<?php
$url = explode('&', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
echo $url[0];
?>

that would then have to rely on the ID being the first part of the url.

<?php

preg_match( '/(id=[0-9]+)/i', $url, $regs);

echo $_SERVER['HTTP_HOST'] . $regs[0];

?>

There we go, should work, havn't tested thou.

Matt

#4 Marxx

    Young Padawan

  • Members
  • Pip
  • 116 posts
  • Gender:Male
  • Location:Finland

Posted 05 December 2006 - 12:59 PM

@Av-

YES! That works fine... Thanks you so much!! :D

@Mr. Matt
You'r didn't work like i need to.. Thing is that script needs to know just that id part and it saves that into file where is another information related to that pic under that id # .. :P

Anyway thanks for both! :D

#5 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 05 December 2006 - 01:09 PM

well my code does nothing different to Av's. Revised and tested this code:

<?php

$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

preg_match( '/(id=[0-9]+)/i', $url, $regs);

echo $regs[0];

?>

If using Av's code and your url is : http://www.mysite.com/index.php?case=254&a...mp;mode=autorun : his code would return case=254 when you are after id=7. My code searches the URL for id=num and returns it in $regs[0]. So my code works better then Av's (Sorry not picking on you or anything Av)

Matt

#6 Ruben K

    Cliff

  • Twodded Staff
  • PipPip
  • 438 posts

Posted 06 December 2006 - 12:55 PM

http://php.net/parse_url

#7 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 06 December 2006 - 01:25 PM

 ?id=7&case=254&mode=autorun

Why not just get it from $_GET['id'], $_GET['case'] and $_GET['autorun']?


EDIT: nevermind.

Edited by SpatialVisionary, 06 December 2006 - 01:26 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users