Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

Redirect in a Php page (joomla)

Hello guys,

how can Redirect to a custom page (article) in joomla in the code below I have some ideas but I am more into .net programming and  have zero  to none skills on php , but I believe this can be done, thanks!!
<?php defined( '_JEXEC' ) or die( 'Restricted access' ); ?>

<?php
    
    $url = JRoute::_("components/com_jquarks/assets/stylesheets/jquarks_style.css");
    $document =& JFactory::getDocument();
    $document->addHeadLink($url, "stylesheet", "rel");
?>

<div class="componentheading">
	<?php echo JText::_('RESULTS'); ?>
</div>

<!-- Rick Modified ........ Old line 11 was echo JText::_('SESSION_RESULTS'); ?> -->


<!-- Score and answers status -->
<?php
    $score = $this->session->score;
    $totalScore = $this->totalQuestions - $this->totalInput + $this->inputEvaluated;
    $percent = $score * 100 / $totalScore;
?>

<!-- Rick Modified  Redirect if less than 100 %--->

<?php
  
 if($score <100 )
 
  { 
  
echo 'Please retake Test ';
  //NEED CODE TO REDIRECT
  
   }
                                         
	
	?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

"Redirect" is often associated with the header("Location: ...") command.  It is a law of HTTP that all headers must come before and be complete before any browser output.  So the concept of putting a header() redirect behind an echo will not work.

You have some choices.  You can use output buffering to catch the browser output.  Then you can issue the header() command.  Your client will not see anything but the redirect.

Or you can use the meta refresh tag with a delay time.  It is deprecated, but works perfectly well.

Or you can give the client the message to retake the test and give the client a clickable link to the URL to retake the test.

HTH, ~Ray
$test = getAllHeaders() ;
will collect all you need

to see what you need :
print_r($test);
Avatar of TonyReba

ASKER

Ray:
" you can give the client the message to retake the test and give the client a clickable link to the URL to retake the test."


, How would I do this???

Line 32:
echo 'Please retake Test ';

And after that, echo the HTML <a href= tag that points to the page where you take the test.
this is my current code which checks a score lower than 100 and then will display a retake link, Or redirect automatically.


if($score <100 )
 
  { 
  
echo 'Please retake Test ';
  //NEED CODE TO REDIRECT

  
   }
                                         
	
	?>

Open in new window

I dont know much php syntax can younplease show me the right sintax??
I think I got something like this pershaps?
<?php
  
 if($score <100 )
 
  { 
    //NEED CODE TO REDIRECT
echo 'Please retake Test ';  
 }
 
?>

<p>
 <a href="index.php?option=com_jquarks&view=quiz&id=1&Itemid=2">Re-take test</a>.
                                        
	

<br />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cool that worked!! how to break line here:


<?php
if( $score < 100 )
{ 

    echo 'A score of 100% is required to pass this quiz. Click the link below to re-take the test' \n;
	
    echo '<a href="index.php?option=com_jquarks&view=quiz&id=1&Itemid=2">Re-take test</a>.'; 
}
 ?>

Open in new window

Thanks for the points.  This ought to do it...

Best regards, ~Ray
<?php
if( $score < 100 )
{ 
    echo 'A score of 100% is required to pass this quiz. Click the link below to re-take the test' . PHP_EOL;
    echo '<br/><a href="index.php?option=com_jquarks&view=quiz&id=1&Itemid=2">Re-take test</a>.'; 
}
?>

Open in new window