Solved

how to get URL variable

Posted on 2003-11-01
7
246 Views
Last Modified: 2006-11-17
i have a problem. i am declaring one variable id  in one site and want to retrive  that id in another site. how can i?
like http://localhost/New%20Site/jeans.php?=1

i want one(1) after the ?= sign.

how to get this variable 1?
0
Comment
Question by:sachinamanath
7 Comments
 
LVL 6

Accepted Solution

by:
aolXFT earned 20 total points
ID: 9662823
I think you need to make yourself slightly clearer in the question.

If you are doing what I think you are trying to do, and just pass arguments you can call the site like

http://localhost/newjeans/site.php?id=1

Then on the other site you can do something like

<?php

$id = $_GET['id'];

?>
0
 

Expert Comment

by:keewooi
ID: 9664936
use $_SERVER['QUERY_STRING'];

eg:

<?

    echo $_SERVER['QUERY_STRING'];

?>
0
 
LVL 2

Expert Comment

by:HeadAcheMike
ID: 9666442
heres a full example of how to pass a variable from one page to the next, it should help you understand how it works better:

file 1 (1.php in example)

<?php
$var = 5;
echo "<a href=\"2.php?variable=$var\">link</a>";
?>

file 2 (2.php in example)

<?php
$newvar = $_GET['variable'];
echo $newvar;
?>

0
 
LVL 7

Expert Comment

by:kohashi
ID: 9714255
      $parts = split ("=", $_SERVER['QUERY_STRING'];);
       $total = count($parts) - 1;
       $fieldyouwant = $parts[$total];


$fieldyouwant will contain that '1' that you needed.  It will not work if there is more than one field being passed.  Then you will have to do $parts[$total-whatever] as well to get the other variables.  It basically splits it apart between = signs.  I cannot remember if a '\' is needed before the '=' sign.  


hope that helps,
-kohashi
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now