0

I'm a bit of a PHP newbie, and I'm trying to do what I believe is quite a complicated operation on a website. So I need your help :)

What I want to do is request a specific page for each client, the only URL variables involved are at the end, as normal.

Basically my variables have been set previously in the script, what I want to say is; The URL is http://site.com/index.php?image=$clientnumber Somehow.

if you guys could give me some insight on how to do this, that would be great!

3
  • 3
    Is your question about "constructing an URL" or about "how to generate a unique client number"? Commented Sep 12, 2012 at 9:46
  • are you setting those variables in the same (php-)script? or are they transfered via a form submit? because most likely you want to have a print_r() look in either $_POST or $_GET Commented Sep 12, 2012 at 9:47
  • It would be helpful to extend your question on what it is you exactly want as @nkr commented, that said, the relevant parts of the source code on what the situation is now, might be a good start to get some answers ;) Commented Sep 14, 2012 at 0:15

3 Answers 3

1

You can use the sprintf function to do this:

$url = sprintf('http://site.com/index.php?image=%s', $clientnumber);
Sign up to request clarification or add additional context in comments.

Comments

1

PHP String Operators

$new_url = "http://site.com/index.php?image=$clientnumber";

or

$new_url = 'http://site.com/index.php?image=' . $clientnumber;

1 Comment

The variable is constant, it comes from a database earlier in the script, I basically need the URL to use in an image frame. It has authentication variables too, but I didn't want to complicate the question.
0
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";

Results in:

foo=bar&baz=boom&cow=milk&php=hypertext+processor

For your needs:

$data = array('image'=> $clientnumber);
echo 'index.php?' . $data;

Will give you:

index.php?image=878787283

1 Comment

That seems like a more graceful solution. For the sake of simplicity I didn't say I was also adding $login and $pass to it. So an array would work significantly better, I think. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.