PHP redirects and conditionals

I have a similar question: OK let me try to make myself clear here.

I have two parts to a website a general side and another part to the site called photography.

Both parts to the site share the same navigation.

For one of the links in the side navigation i have a link called FAQ’s.

Rather then have 2 different faq links shown I want to create a conditional that if your on the general side of the site go to the general faq and if your on the photography side go to the photo faq.

so something like this i think:

if (gen1.php, gen2.php, gen3.php)
{ go to this gen-faq.php page }

else if (photo1.php, photo2.php)
{go to this photo-faq.php page}

Im not sure if this is the way I would even go around doing this. BUT COULD SOME ONE PLEASE HELP ME WITH THIS PROBLEM

thanks

Hi, this is where sone of the SERVER variables can help you.

$_SERVER[‘REQUEST_URI’] will tell you the name of the page you are on. You can then use this to server the right link.

Server vars: http://php.net/manual/en/reserved.variables.server.php

eg


if(preg_match('|(photo1.php|photo2.php)|', $_SERVER['REQUEST_URI'])) {
    //serve the link for photo-faq.php page
} else {
    //serve the link for gen-faq.php page
}

alternatively you could use $_SERVER['‘HTTP_REFERER’] to see which page they came from and redirect accordingly but thats not always reliable.

So did i do this right then?

<?php
if(preg_match(‘|(w-gallery.php|w-services.php)|’, $_SERVER[‘REQUEST_URI’])) {
//serve the link for photo-faq.php page
(‘w-faq.php’)

} else {
//serve the link for gen-faq.php page
(‘gen-faq.php’)
}
?>

Did it work? :stuck_out_tongue:

NOPE! lol

it gave me and error: Parse error: syntax error, unexpected ‘}’ in /- on line 6

this is my code with the php im trying to use

<div id=“side-nav”>
<div id=“firstpane” class=“menu_list”> <!–Code for menu starts here–>
<p class=“menu_head”>Services</p>
<div class=“menu_body”>
<a href=“g-services.php”>General Services</a>
<a href=“w-services.php”>Wedding Services</a>
</div>
<p class=“menu_head”>Gallery</p>
<div class=“menu_body”>
<a href=“g-gallery.php”>General Gallery</a>
<a href=“w-gallery.php”>Wedding Gallery</a>
</div>

</div> <!–Code for menu ends here–>

<ul id=“side-limenu”>
<li><a href=“testimonial.php”>Testimonials</a></li>
<li><a href=“contact.php”>Contact Us</a></li>
<li><a href=“faq.php”>FAQ’s</a></li>

</ul></div>

<?php
if(preg_match(‘|(w-gallery.php|w-services.php)|’, $_SERVER[‘REQUEST_URI’])) {
//serve the link for photo-faq.php page
(‘w-faq.php’)

} else {
//serve the link for gen-faq.php page
(‘gen-faq.php’)
}
?>

Think about the following code:

if(preg_match('|(w-gallery.php|w-services.php)|', $_SERVER['REQUEST_URI'])) {
//serve the link for photo-faq.php page
('w-faq.php')

} else {
//serve the link for gen-faq.php page
('gen-faq.php')
}

Those brackets aren’t under a spell, PHP doesn’t have a clue what to do with them :stuck_out_tongue:

<?php
if(preg_match('|(w-gallery.php|w-services.php)|', $_SERVER['REQUEST_URI'])) {
    echo "<a href="w-faq.php" title="Photo FAQ">Photo FAQ</a>";
} else {
    echo "<a href="gen-faq.php" title="General FAQ">General FAQ</a>";
}

lol you might want to check those quotes Jake :wink:



<?php

if(preg_match('|(w-gallery.php|w-services.php)|', $_SERVER['REQUEST_URI'])) {
    echo '<a href="w-faq.php" title="Photo FAQ">Photo FAQ</a>';
} else {
    echo '<a href="gen-faq.php" title="General FAQ">General FAQ</a>';
}


Darn, I’ve been using Java today so double quotes are hammered into me :stuck_out_tongue:

</excuse>