I wish to pass a variable between pages using $_POST (not because of security, I just dont want it to be part of the url). Is there a way I can do this without using a <form>? For the moment, I've given up and am just using $_GET, but it makes the url a little ugly.
You could probably rig something up with AJAX to keep things off of the URL, but you'ld technically still be using a <form> even though it would be a script-generated <form>. Probably more trouble than it's worth really.
I guess because I'm still rather new to PHP (and programming in general) and dont know very much about sessions... I guess this is a perfect time to learn though. Thanks for the help.
cURL <?php $url = "url here"; $data = "field1=1&field2=2"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $return = curl_exec($ch); curl_close($ch); ?> Code (markup):
@1368633: Yeah.. that's not going to help much with what they're asking. Submitting some POST data to some URL through the back-end won't help them keep variables for the current user as they browse pages. @EricBruggema: The OP stated that they do not want to use forms and that they want to avoid using GET because it looks ugly. Why would they want to combine both methods they're trying to avoid! As JAY6390 and Kyosys said, go with session variables. Very easy. Just make sure you call the session_start() function before ANY data gets output, otherwise you'll get a "Headers already sent" parse error. Then when you want to store a value that you can easily grab the next time they load a page (if the session hasn't expired), you'd just do $_SESSION['variable_name'] = "value"; and can access it with the same method. It's basically like using setcookie() and accessing it with $_COOKIE[''] since it technically IS setting a cookie on their side (just to say what their session ID is; the actual values are stored server-side so no worries about any important data being peeked through by your users unlike with using actual cookies!). Good luck.
I will help you in simple manner: start the session by- session_start(); //this line should be the first line of the code pass the values to a session variable- $_SESSION['login']="usertest"; now use the session variable on another page- $x=$_SESSION['login']; //remember to start the session before this line. Regards Shishir Gupta Salah Software