How to pass the http://url ID= to my $url.custom code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

How to pass the http://url ID= to my $url.custom code

Post by danjapro »

I am trying to get the variable ("&Id= Id number (ex.&Id=25)") to be part of the $url string in code, with it taking the ID from the http:// url to page in browser that is being passed from user page link.

All I need is to collect the "Id" see code below tell me what I am missing or need to add please


I added this line and it is worng '$url.=$custom.'&Id=$id';'

Code: Select all

/* Getting parameters like task, view, layout, etc. */
	$re1='.*?';	
	$re2='(?:[a-z][a-z0-9_]*)';	
	$re3='.*?';	
	$re4='((?:[a-z][a-z0-9_]*))';	
	$re5='.*?';	
	$re6='((?:[a-z][a-z0-9_]*))';	
	if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
		$type=$matches[1];
		$layout=$matches[2];
	}
	/* end */
	
	/* Creating URL */
	$url=JURI::root().'index.php?'.$component.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&'.$type[$i].'='.$layout[$i];
	}
	$url.=$custom;
	//$url.=$custom.'&Id=$id';
	/* End */
	
	/* Getting current User Logged in  Session ID and First Album Id */
	$session=&JFactory::getSession();
	$session_id=$session->getId();
	$id=$session->getId();
	/* End */
	
	/* Starting curl session */
	$c_open=curl_init();
    curl_setopt($c_open, CURLOPT_URL , $url);
    curl_setopt($c_open, CURLOPT_HEADER, 1);
	curl_setopt($c_open, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($c_open, CURLOPT_COOKIE, session_name().'='.$session_id );  
	// Passing session ID.
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: How to pass the http://url ID= to my $url.custom code

Post by danwguy »

Where in that are you defining the values for $custom or $component? I didn't see them defined anywhere, just called to.
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: How to pass the http://url ID= to my $url.custom code

Post by danjapro »

Se I am define the Id as the jRequest Var from url, then passing it as vaiable $id, yet. it not adding it to the $url=$custom.
HOW can I get it to display, it shoing in the broswer http:// url part, it just needs to read that &id=25, Id=26, etc...

Code: Select all

// no direct access
defined('_JEXEC') or die ('Restricted access');
/* Getting Parameters */
$component= $params->get('component','');
$view= $params->get('views','');
$custom=$params->get('custom','');
$auto=$params->get('autojscss','0');
$js=$params->get('customjs','');
$css=$params->get('customcss','');
$head_js=$params->get('custombodyjs','');
$head_css=$params->get('custombodycss','');
$id      = JRequest::getVar($prefix . 'id') ;
/* End of Parameters */

$type=array();
$layout=array();
if($component!=''){
	/* Getting components parameters like task, view, layout, etc. */
	$re1='.*?';	
	$re2='(?:[a-z][a-z0-9_]*)';	
	$re3='.*?';	
	$re4='((?:[a-z][a-z0-9_]*))';	
	$re5='.*?';	
	$re6='((?:[a-z][a-z0-9_]*))';	
	if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
		$type=$matches[1];
		$layout=$matches[2];
	}
	/* end */
	
	/* Creating URL */
	$id = JRequest::getVar($prefix . 'id') ;
	$url=JURI::root().'index.php?'.$component.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&'.$type[$i].'='.$layout[$i];
	}
	//$url.=$custom;
	$url.=$custom.'&Id=$id';
	/* End */
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: How to pass the http://url ID= to my $url.custom code

Post by danwguy »

if it's showing up in the url just use something like $custom = $_GET['id']; and it will pull that value from the url and save it as $custom, then you can use that anywhere you want.
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: How to pass the http://url ID= to my $url.custom code

Post by danjapro »

I dont understand, If I place

Code: Select all

$custom = $_GET['id'];

then wont that mess up my string

Code: Select all

$url.=$custom.'&Id=$id';
Where woudl i incldue this to have ti print ID anywhere. Where i can use <?php echo $id;?>????
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

Re: How to pass the http://url ID= to my $url.custom code

Post by danwguy »

What I was saying is, if you are saying that you can see the Id=25 in your browser then all you have to do, on the page that you want to use that variable is use

Code: Select all

$whatever = $_GET['id'];
Then when you need it on that page you can say something like

Code: Select all

echo "Your ID is: " .$whatever;
that will out put
Your ID is: 25
I hope you are understanding that, and I hope I am understanding what you are saying as well. You had said that it goes to the url just fine, so I am assuming you just want to get that variable from the url, that is where $_GET comes in, you use $_GET to grab whatever you want from the url... Example: http://www.yoursite.com/test.php?var1=30&Id=25
on test.php you would put

Code: Select all

$whatever = $_GET['Id'];
now $whatever is 25.
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: How to pass the http://url ID= to my $url.custom code

Post by danjapro »

Thanks that correct. I got that.
added this code give to me, but I it should eb able to state3 if id->0 or null then else not just ID

Is this correct

Code: Select all

	if(isset($_GET['id']) && is_numeric($_GET['id']))
              {
               if(intval($_GET['id']) === null){
                echo '$id is a null and belongs to Administrator';
              }
         else
          {
        echo "NO ALBUM ID FOUND. SORRY.";
       }
                    /* Creating URL */
	$Id=JRequest::getVar($prefix . 'id') ;
	$url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&'.$type[$i].'='.$layout[$i];
	}
	
	$url.=$custom;
	//$url.=$custom."&id=$id";
	/* End */
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: How to pass the http://url ID= to my $url.custom code

Post by danjapro »

I wrote this below, to get the userid that is in the browser to SQL query against the user_id in album table and get the $album_id or $id.

When my url in the browser is looks like:
"http://localhost/index.php?option=com_c ... x[b]&id=xx[/b]&Itemid=xx" .. This works fine.

But I want to work without the "&id=xx", just like this
"http://localhost/index.php?option=com_c ... x&temid=xx"

SEE CODE

Code: Select all

if (!isset($_GET['userid']))
		{
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
        $userid = $user->id;

		
		$id = $_GET['userid'];
		$query = 'SELECT user_id, id, format_id, year, name FROM #__muscol_albums WHERE user_id = ' . $id;
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		$result = mysql_query($query) or die('Error, No Album Search failed');
		list($name, $user_id, $id, $year) = mysql_fetch_array($result);
	
	
		//$db =& JFactory::getDBO();
		//$user =& JFactory::getUser();
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		$db->setQuery($query);
		$album_id = $result();		
	
		echo $id;
		echo $user_id;
		echo $year;
		//exit;
		}	 
	 		
	/* Creating URL */
	$id=JRequest::getVar($prefix . 'id') ;
	$url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&'.$type[$i].'='.$layout[$i];
	}
	
	$url.=$custom;
	//$url.=$custom."&id=$id";
	/* End */
	
	/* Getting current User Logged in  Session ID and First Album Id */
	$session=&JFactory::getSession();
	$session_id=$session->getId();
	$id=$session->getId();
	/* End */
	
	/* Starting curl session */
	$c_open=curl_init();
    curl_setopt($c_open, CURLOPT_URL , $url);
    curl_setopt($c_open, CURLOPT_HEADER, 1);
	curl_setopt($c_open, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($c_open, CURLOPT_COOKIE, session_name().'='.$session_id );  
	// Passing session ID.
    
	$result=curl_exec($c_open);
    curl_close($c_open);
    /* End of curl session */
danjapro
Forum Commoner
Posts: 72
Joined: Mon Sep 27, 2004 10:56 am

Re: How to pass the http://url ID= to my $url.custom code

Post by danjapro »

please take a look at code below.. IAm trying to parse the userid from borwser to matcht eh user_id in table in DB then reutn it vaues, especially value for ID

HELPPPP

Code: Select all

// no direct access
defined('_JEXEC') or die ('Restricted access');

/* Getting Parameters */
$component= $params->get('component','');
$view= $params->get('views','');
$custom=$params->get('custom','');
$auto=$params->get('autojscss','0');
$js=$params->get('customjs','');
$css=$params->get('customcss','');
$head_js=$params->get('custombodyjs','');
$head_css=$params->get('custombodycss','');
$id      = JRequest::getVar($prefix . 'id') ;
/* End of Parameters */



$type=array();
$layout=array();
if($component!=''){
	/* Getting components parameters like task, view, layout, etc. */
	$re1='.*?';	
	$re2='(?:[a-z][a-z0-9_]*)';	
	$re3='.*?';	
	$re4='((?:[a-z][a-z0-9_]*))';	
	$re5='.*?';	
	$re6='((?:[a-z][a-z0-9_]*))';	
	if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6."/is", $view, $matches)){
		$type=$matches[1];
		$layout=$matches[2];
	}
	/* end */
	
    /* Passing Album Id from URL in borwser
		
      if(isset($_GET['id']) && is_numeric($_GET['id']))
              {
               if(intval($_GET['id'])=== null){
                echo '$id is a null and belongs to Administrator';
              }
         else
          {
        echo "NO ALBUM ID FOUND. SORRY.";
       }
			  
	}
	 */
	 
		if (!isset($_GET['userid']))
		{
		$db =& JFactory::getDBO();
		$user =& JFactory::getUser();
        $userid = $user->id;

		
		$id = (!isset($_GET['userid']));
		$query = 'SELECT user_id, id, format_id, year, name FROM #__muscol_albums WHERE user_id = ' . $id;
		//$query = 'SELECT user_id FROM #__muscol_albums WHERE id = ' . $album_id ;
		$result = mysql_query($query) or die('Error, No Album Search failed');
		list($name, $user_id, $id, $year) = mysql_fetch_array($result);
	
	 
		
	
		echo $id;
		echo $user_id;
		echo $year;
		//exit;
		}	 
	 		
	/* Creating URL */
	
	//if (!empty($_GET['id']) && (intval($_GET['id']) == $_GET['id'])) { 
	//     $url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	//} else {
    // $url=JURI::root().'index.php?'.$component.'&id=1&tmpl=component&print=1'; //redirect      is a function 
	 
	//}
	$id=JRequest::getVar($prefix . 'id') ; 		
	$url=JURI::root().'index.php?'.$component.'&id='.$id.'&tmpl=component&print=1';
	for($i=1;$i<count($type);$i++){
		$url.='&'.$type[$i].'='.$layout[$i];
	}
	
	//$url.=$custom;
	$url.=$custom."&id=$id";
	/* End */
	
	/* Getting current User Logged in  Session ID and First Album Id */
	$session=&JFactory::getSession();
	$session_id=$session->getId();
	$id=$session->getId();
	/* End */
Post Reply