homepage Welcome to WebmasterWorld Guest from 54.234.74.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
how to pass php variable to ajax?
rigaconnect




msg:4540619
 4:52 pm on Jan 30, 2013 (gmt 0)

Please, explain or give link how to pass php variable to ajax?

php $ifloggedin = $_SESSION['loggedin'];

in ajax
if $ifloggedin equals to 1, then redirect
like here
if($ifloggedin == 1) {
window.location = "login-success.php";
}

but it does not work... i do not understand

 

daveVk




msg:4540778
 12:16 am on Jan 31, 2013 (gmt 0)

The value from $_SESSION['loggedin'] needs to be transferred from the server PHP to the client by including it somewhere in the PHP generated HTML or PHP generated Javascript with
<?php echo $_SESSION['loggedin']; ?>

Within Javascript maybe

var ifloggedin = <?php echo $_SESSION['loggedin']; ?>;

OR

if(<?php echo $_SESSION['loggedin']; ?> == 1) {
window.location = "login-success.php";
}


Within HTML maybe

<script>
var ifloggedin = <?php echo $_SESSION['loggedin']; ?>;
</script>

swa66




msg:4540862
 9:37 am on Jan 31, 2013 (gmt 0)

I'd make sure to properly escape any user generated input before outputting it in a script context. XSS is really close by if you don't.

See rule 3: https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet

rigaconnect




msg:4540864
 9:43 am on Jan 31, 2013 (gmt 0)

Thanks for information.
Then seems for login form better not use ajax...
Better use only php for processing.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved