Using PHP in a javascript menu to redirect if no SESSION_NO?

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
MaineWebGirl
Forum Newbie
Posts: 1
Joined: Wed Apr 16, 2003 9:54 am

Using PHP in a javascript menu to redirect if no SESSION_NO?

Post by MaineWebGirl »

I have a javascript menu with this call (and many other similar):
http://64.179.21.93/cgi-bin/nl/nldemo.b ... ASK=IIMXKS

the "SESSION_NO" part of the call tells our system the username and password of the customer logged in. If you haven't logged in, either with username and password or as a new customer, you have no session number. I would like the call above to be able to check for a session number and, if there isn't one, redirect the user to this call instead:
http://64.179.21.93/cgi-bin/nl/nldemo.b ... _id=clogin

I was told that I could use PHP:
<? if (session_id=="){do thelogin ;} ?> but I don't know anything about PHP at all. Even if that is exactly the right command I don't know where to put it.

Somebody at another forum suggested a redirect PHP, but it seems to me that would redirect people to the login page even if they were just going to a non-logged in page and I don't want that, just when they select an option on the menu like the one above.

PS-If you try that first link with the session_no, it will probably be timed out. IF you wanted to try it out, you could go to the second link and use the new customer link and go from there.

Any ideas? It would be greatly appreciated!!!! :roll:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please read: Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+

Code: Select all

<?php
// TODO: function validNO checks wether the passed argument is a valid session_no

// if either SESSION_NO hasn't been passed via GET or it is not a valid session_no
if (!isset($_GET['SESSION_NO']) || !validNO($_GET['SESSION_NO']) )
{
   do_the_login();
}
?>

You might also be interested in http://www.zend.com/zend/tut/session.php
Post Reply