tags:

views:

117

answers:

4

I have an on line project "question of the week"; this project allows the users to submit their questions. These questions are saved in a mysql table; the question is also sent over to another simplepost.php which stores the question in a phpBB. I want to use this phpBB for every question, for discussions on that question.

So now, my project stores the question in sql table as well as posts the question in the phpBB.

But when the question is posted in phpBB it stores in it "http://servername.com/phpBB3/viewtopic.php?f=5&t=24" where t=24 is the question.

I somehow want to grab this url and extract the t=24, so that I can have a click able link for each question in my project that directs the question of its particular phpBB page.

Suppose my project is on: http://servername.com/qotw/profile.html (this allows the user to post a question and the question is inserted in sql table and also calls in phpBB/simplepost.php is posts the question in phpBB)

and this question in php can be seen on : "http://servername.com/phpBB3/viewtopic.php?f=5&t=24"

Please suggest to me what should I do. how can I grab this "t=24" from this url.

When my simplepost.php is called, is posts the question using posting.php and a return value is sent back.

The code in simplepost.php looks like:

$title = "This is the title of the message.";
//$body = "This is the message body.";
$post_fields = array(
          'subject'   => $title,
          'addbbcode20' => 100,
          'message' => $body,
          'lastclick'          => $lclick[0],
          'post'   => 'Submit',
          'attach_sig'        => 'on',
          'creation_time'      => $lclick[0],
          'form_token'   => $security123[1],
          'filecomment' => '',
          );

//Wait (you might also do this by setting lastclick in the past by 3 seconds
sleep(3);

//Set up curl session for posting the message
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL,$purl);
curl_setopt($ch1, CURLOPT_POST, true);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch1, CURLOPT_HEADER, false );
curl_setopt($ch1, CURLOPT_COOKIE,'cookie.txt');
curl_setopt($ch1, CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch1, CURLOPT_COOKIEFILE,'cookie.txt');
$result2= curl_exec ($ch1);
//$result3= curl_exec ($ch1, CURLOPT_URL,$purl);
curl_close ($ch1);

echo $result2;

The respond come in $result2. and the pages goes over to http://servername.com/phpBB3/viewtopic.php?f=5&t=24".

But the thing is all this is happening in the back end. My project does not shows the viewtopic.php page of the phpBB.

+1  A: 

Hi,

To extract components from the URL, you can use parse_url -- well, if you only want to get the query string, $_SERVER['QUERY_STRING'] will do just fine too.

Then, to get the params/values from the query string, you can have a look at parse_str : there is an example that shows just what you want :

<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz

parse_str($str, $output);
echo $output['first'];  // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz
?>

Obvisouly, you will probably prefer the second way, to avoid injection of (unknown and potentially dangerous, like register_globals) variables in your script.

Pascal MARTIN
ah, you beat me to it..
Tom Haigh
+1  A: 

Not really sure what you want, but I may be being stupid.

Given a url in $url you could do this:

$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
$t = $params['t'];

If the page is passed the GET parameter, you could do:

$t = $_GET['t'];
Tom Haigh
+2  A: 

If I'm not mistaken you should be able to use PHP to get the 'value' (24) stored in the 't' variable in the URL using $_GET['t']. This will only work if you are currently at that URL though. See: http://us2.php.net/manual/en/reserved.variables.get.php

if you are trying to grab just that section when you are not on that specific page you could try:

ereg("t=[0-9]+", $url, $res)

then just strip off the "t=" from the result in the $res array

Phil Vollhardt
A: 

How about:

$var = $_GET['t'];

Filter it and do whatever with it.

Elzo Valugi