Hi Guys, I am fairly new to PHP, and I recently changed my whole site to use PHP sessions, which worked fine.
Then I added PHP parts in my pages that display different menu choices depending on if a PHP session exists. This also works fine, until I found that any HTML/PHP pages that have form/submits no longer work, and I get kicked back to the index.php
After slow backtracking, I removed new parts, and found the forms started working again if I removed the PHP part that chooses which JavaScript file to reference, as follows from contact.php
<?php
if (isset($_SESSION['SESS_MEMBER_ID'])){
echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"menu_horz.js\"></script>";
}
else {echo "<script language=\"JavaScript\" type=\"text/javascript\" src=\"log_menu_horz.js\"></script>";
}
?>
I tried changing the echo ".." to use single quotes ' ' instead, but then it doesn't work at all then with a form or no form on the page. I assume I am doing something wrong, but I can't find any resources that give me a definitive way of referencing Javascript files. What freaked me out was only the ones with forms were an issue.
I am using <?php session_start(); ?> at the beginning of every page (before any output). Other PHP code on the page is working fine. Only the above part seems to be the problem, and works too, as long as I don't submit a form.
- Could it be more weirder :-)
- I tried also to find a workaround, but it would mean having PHP inside my JavaScript file, but I am not sure it would work, since JS is client side, and PHP server... Essentially, I just want to run certain JS menus depending if the person is logged in or not.
- Example contact.php attached
Any ideas of what the problem might be with the code above?
Will be grateful for any help you can give.
Regards
D
[attachment deleted by admin]