Michael
Michael

Reputation: 55

Use a javascript function in php

I have a nav bar on my site that has dynamic links. When the user is logged out, I want these links to say "Register | Log in" and when they are signed in, I want those same links to change to "$userName | Account". I have a script to handle this, but there is one problem.

When the user is signed out, I want the "Register" link to open a popup div with the registration page on it, instead of forwarding them to a different page. The only problem is, the way I am handling this is in a link like

<a href="#" onClick="popup('popUpDiv')">Register</a>

But I need to call this in a php script.

Any Help is appreciated.

This is from the php script.

 if (!isset($_COOKIE['idCookie'])) {
 $logOptions = ' <a href="http://' . $dyn_www . '/register.php">Register</a>
 &nbsp;&nbsp; | &nbsp;&nbsp; 
 <a href="http://' . $dyn_www . '/login.php">Log In</a>';

}

But instead of having the whole register.php, i just want it to go to

<a href="#" onClick="popup('popUpDiv')">Register</a>

Upvotes: 0

Views: 135

Answers (3)

Tarik
Tarik

Reputation: 81721

Try something like this :

<?php
if ($ID = '') {
echo "<script language=javascript>alert('Please enter a valid username.')</script>";
}
?>

Upvotes: 0

Brian Patterson
Brian Patterson

Reputation: 1625

I think what you want to use if you are looking to do it in php is this ...

header('location: http://yoururl.com/page.php')

Sorry if I don't understand the question completely. Posting some code would help.

Hope this helps :)

Upvotes: 1

mch_dk
mch_dk

Reputation: 369

Simply do a server-side check around the HTML you want to output. PHP is parser based.

Upvotes: 0

Related Questions