Welcome to WebmasterWorld Guest from 107.20.59.213

Forum Moderators: open

Message Too Old, No Replies

how to pass php variable to ajax?

     

rigaconnect

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

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

WebmasterWorld Senior Member 5+ Year Member



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

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

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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: [owasp.org...]

rigaconnect

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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month