PHP - Session Problem Over Multiple Domains
I have recently changed server and setting things up are a right pain, after 2 days im need of some help.
I have my site split into sub domains so lets say; www.domain.com one.domain.com two.domain.com three.domain.com They are to separate parts of my site which used to make it easier the manage each part, so one sub domain handles accounts and logins etc.. whilst another handles products and so on. the problem im having is all my login scripts and are on say 'one.domain.com', i can log in fine but when i visit any other domain im logged out, i can't seem to sort it out. i have tried setting my session cookie path and session cookie domain by painstakingly adding Code: [Select] ini_set('session.save_path', '/var/www/vhosts/website.co.uk/httpdocs/tmp'); ini_set('session.cookie_domain', '.website.co.uk'); to every page, but it makes no difference, im also getting the occasional error Code: [Select] Warning: session_start() [function.session-start]: open(/tmp/sess_d387ha6eqvj53f135q0fh4d733, O_RDWR) failed: Permission denied I have contacted my server provider by after endless messages they are no longer helping but rather keep saying 'leave it with us' then 'we fixed it' although they didnt. It doesn't help im so limited in what i have access to, i cant access the php.ini so everything has to be done via php So i would really appreciate any help getting this session problem sorted out. Thank you. Similar TutorialsSuppose I have two versions of the same website; one American and one Canadian. This site has members with profiles etc. The way my site is written, I think that if someone were to login to their account on, say, the American site, then a session variable would indicate that a user is logged in on the client machine. Now if they visit the "profile" page, for example, or some other members-only page ON THE CANADIAN SITE, and start manipulating data etc., then this would affect the databases for the Canadian site, and everything would get screwed up (actually, I think mysql would just start spitting out errors, but that's not good either). Does anyone have some simple way to deal this this kind of thing? I don't really know exactly how session variables work. Say I have two domains, somepage.com and somepage.ca on the same server/DNS. If a page on somepage.com sets a session variable called $_SESSION['somevar'], and a page on somepage.ca also sets a variable called $_SESSION['somevar'], are the two variables somehow distinct because they are on different domains? Like, if somepage.com sets the variable, then somepage.ca check if the variable is set, what will happen? What if I wanted to set up the two pages in subfolders, like somepage.com/us and somepage.com/ca, how would I deal with distinguish session variables for the two sites? Is one approach (i.e. distinct domains vs subfolders) better than the other? Thanks, Good Day, I'm using the following example script from http://php.net/manual/en/function.session-set-save-handler.php which I have placed in session-handler.php and is included at the top of my index.php file. I have multiple domain names for the same website, so naturally when a person logs into the site, I would like the session to be active across all the domains instead of them having to login again if say they go from mysite.com to mysite2.com. session-handler.php <?php function open($save_path, $session_name) { global $sess_save_path; $sess_save_path = $save_path; return(true); } function close() { return(true); } function read($id) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; return (string) @file_get_contents($sess_file); } function write($id, $sess_data) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; if ($fp = @fopen($sess_file, "w")) { $return = fwrite($fp, $sess_data); fclose($fp); return $return; } else { return(false); } } function destroy($id) { global $sess_save_path; $sess_file = "$sess_save_path/sess_$id"; return(@unlink($sess_file)); } function gc($maxlifetime) { global $sess_save_path; foreach (glob("$sess_save_path/sess_*") as $filename) { if (filemtime($filename) + $maxlifetime < time()) { @unlink($filename); } } return true; } session_set_save_handler("open", "close", "read", "write", "destroy", "gc"); session_start(); ?> The script above doesn't appear to be throwing any errors, and I can login like normal but it doesn't seem to be saving the sessions at all. So I still have to login to each separate domain. Any ideas? Thanks, Ace I'm looking for a secure way to share session data across two different domains (not subdomains) on the same server. I've looked at passing the session id through a GET var to the other domain. It works but it looks to open the possibility of session hijacking and I don't really like having the session id in the URL string. Any way to make this secure? The other option I'm looking at is using cURL to load a script on the other domain that sets a cookie with the session id. When the person loads the other domain, check for the cookie, get the session id, connect to session then delete the cookie. Can anyone see anything wrong with this? Thanks. hi guys i need a script i can use on a website that redirect all domains to a specific URL+domain
so here is the goal to achieve:
i want to redirect DOMAIN1.com DOMAIN2.org DOMAIN3.com .... to my main domain MyredirectDomainurl.com and on MyredirectDomainurl.com i need to run a script that will FORWARD DOMAIN1.com ===> https://www.afternic.com/domain/DOMAIN1.COM DOMAIN2.ORG ===> https://www.afternic.com/domain/DOMAIN2.ORG DOMAIN3.com ===> https://www.afternic.com/domain/DOMAIN3.com
thanks for your help Hal
Edited January 1 by kahymo typo Hello everyone, I'm sitting here in a position where I can't work on my site or test any code, but my mind is racing about what I can do to solve a particular problem that I have. I won't get into the problem because it would take more time to type than I have right now, but I have an idea for a simple solution, just not sure if it will work or not. So, here's my question: Is it possible to have multiple session variables during a session? Such as: $email=$_SESSION['email']; $user=$_SESSION['userid']; If this is possible, my problem is solved (I think)... otherwise, I have to keep thinking about it. Thanks for any help! I'm not sure how to approach this but here is my problem. I'm using a sql statement that counts the number of users in the database. I've created a session variable named $MerchantCount and then I need to multiple that number by this scheme 0-9 Needs to multiple by 2.5 10-19 Needs to multiple by 5.0 20 and up needs to multiple by 7.5 How would I do this? Thanks... I have the following session variables for each item in a cart, which gets updated each time an item is added from the catalog // Register the session variables $_SESSION['ses_basket_items']=$ses_basket_items; $_SESSION['ses_basket_name']=$ses_basket_name; $_SESSION['ses_basket_amount']=$ses_basket_amount; $_SESSION['ses_basket_price']=$ses_basket_price; $_SESSION['ses_basket_stockcode']=$ses_basket_stockcode; $_SESSION['ses_basket_image']=$ses_basket_image; $_SESSION['ses_basket_size']=$ses_basket_size; $_SESSION['ses_basket_sizechoice']=$ses_basket_sizechoice; $_SESSION['ses_basket_id']=$ses_basket_id; I have a current cart page which loops through the sessions and displays them in a form. I have a check box for each item with the name="remove[]" and the value is the itemID which is the $ses_basket_id of item in the session. I have a select box with name="size[]" and the value is the users selected size for each item in the session which is $ses_basket_size Finnally I have a quantity text box with name="quantity[]" and the value is the users quantity value selected which is $ses_basket_amount. After all the looping through the products displaying each item in a row I have an update cart submit button name="change" outside the loop. What I want to know is how do I setup to perform each of these actions for each item in the session, how do I create the foreach loops for each array to delete or modify the correct items in the session if they are modified. I have the code to perform each task but dont know how to loop it through for each item in the session affecting only the correct session items. so if I have 3 items in the session for example, and I want to change the size of item 1, remove item 2 and change item 3 for quantity 1 to quantity 3 with only the 1 form and change button for all items and actions? Hope that makes sense any help with this would be appreciated. This could be a silly question and it may not be very relevant here, forgive me if that is the case. When you have a domain like http://example.com and you then have a sub domain like http://something.example.com how is that achieved? Is it to do with the way the site is coded or structured? Hello all, it's been a while! Good to be back. I am having trouble with a script I'm trying to modify to seach for domains with specific extensions. Now, I have never done any domain checking before and I'm a little bewildered. The script uses an array and checks the input against each extension using the array. Each line looks similar to: Code: [Select] '.com' => array('whois.crsnic.net','No match for'), What does the whois.crsnic.net mean? I assume it's a register/database of domains? Hey All, What I am trying to do is link a whole bunch of our sites together to be seamless when users are on them, even though they are actually on different servers. For example, we have portal.ourdomain.com which runs our billing software, www.ourdomain.com which is our regular website, cp.ourdomain.com which is our control panel and mail.ourdomain.com which is our webmail login. We have a common header, which needs the session variables and such from the portal site. So we created a separate header file (on the portal site) that could be used by the other sites to read in. Now the separate file works by going to it directly portal.ourdomain.com/commonheader.php, however when included on the external pages, it doesn't get the number of items in the cart or the logged in state. I assume that this probably has to do with the sessions, but my question is, is there a way to process the file before it is included. I was hoping that it could read the file output, rather than generate it within the external site. Let me know if any one of you know of any ways to do what I am trying. If I am confusing you, just let me know what needs clarification. Thanks. Hello Everyone! I'm new to the forum and new to PHP. I'm curious about the limitations of PHP. I'm working a project that I'm not even sure is possible in PHP. The project is simple: I need a page that can track business reviews on external sites and report that activity to a database. Below is a simple mockup of the html. Code: [Select] <html> <head> <title>Boomerang Project</title> </head> <body> <h1>Like Our Work?</h1> <h2>Help Spread The Word.</h2> <p>Click on the links below to start writing a review about the service that we have provided you.</p> <h3>Complete 5 reviews recieve a gift certificate.</h3> <ul> <li><a href="" target="_blank">Yahoo</a></a></li> <li><a href="" target="_blank">Google</a></li> <li><a href="" target="_blank">Yelp</a></li> <li><a href="" target="_blank">Manta</a></li> <p>You have completed <!--Number-of-Reviews-Completed-->. <br /> <br /> <!--The form below doesn't appear until at least 5 reviews are confirmed to have been posted. At which point a script will reconfirm the postings and send 2 emails, one to business with client info and another email to client confirming the completion of the postings.--> <form> <fieldset> <label for="name">Name</label><input type="text" name="full-name" /><br /> <label for="address">Address</label><input type="text" name="address" /><br /> <label for="city">City</label><input type="text" name="city" /><br /> <label for="state">State</label><input type="text" name="state" /><br /> <label for="zipcode">Zip Code</label><input type="text" name="zipcode" /><br /> <label for="telephone">Telephone</label><input type="text" name="telephone" /><br /> <label for="email">Email</label><input type="text" name="emaile" /><br /> <input type="submit" /> </fieldset> </form> </body> </html> how would i go about doing this? lets say i want to use different domains i.e.: mysite.com mycoolsite.com but i want them to both use the same php script i.e.: myscript.com/site.php?domain=mysite.com each site will show different content depending on the domain $_GET variable... can anyone help me with this? Hello
I'm new in PHP but I need a help If it possible.
I want to Know which domain used my php script .
For example when some one run installer or run index.php an email send to me that contain the domain name.
Or some thing like this that I used for any php code.
so thanks
First of all, does anyone know of some good documentation to better understand cookies? I've gone through the PHP manual, and can find how to use PHP to work with cookies, but not how cookies really work.
In particular, it is my understanding that if the domain is .mydomain.com, then mydomain.com, www.mydomain.com, or whatEver.mydomain.com, cookies could be set for each, and available for each, right?
If path was /, cookies will be sent for mydomain.com, mydomain.com/bla, and mydomain.com/bla/bla. If path was /bla, cookies will be not be sent for mydomain.com, but will be sent for mydomain.com and mydomain.com/bla/bla.
Also, what would be the impact if Apache rewrote bla.mydomain.com to mydomain.com/bla?
Please feel free to provide any other insight on this topic.
Thank you
I recently installed a SSL certificate for one of my domains, on a hosting account that includes several other domains. To redirect visitors to the SSL version of the website (because the SSL certificate only works for the www. version of the site) I use the following code in my .htaccess file:
#First rewrite any request to the wrong domain to use the correct one (here www.) hey all, i've got no experience with php or apache coding but would really appreciate some help. basically, all i want to do is add a parked domain so that website2.com redirects to website1.com when i try to do this with cPanel i get the following message (Apache detected an error in the Rewrite config. Syntax error on line 5 of /public_html/.htaccess.Ei15veHhUrcxOtEJvtu0jaH_2_TPSZ8u: RewriteRule: bad flag delimiters Please try again.) i opened .htaccess but have no idea what to change in it to fix this issue all that is .htaccess contain is the following RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) - [PT,L] RewriteRule ^(.+) index.php any help would be really appreciated. thanks. Hello Everyone! I have 2 problems with sessions that I'd like some assistance with. 1. The session often ends after clicking any link after logging in. (sometimes it remains alive, and in those cases it stays alive until browser is closed.) 2. The function that should start a session if a cookie is found (and correct) is not working, so if the browser is closed and re-opened the session won't start the session. I'll include the code that I think is relevant. The odd part is that these problems occur in every browser, I have tried multiple tutorials (so different scripts) to creating a login form but somehow the same result appears every time. function login($username, $password, $remember = false) { $sql = mysql_query("SELECT * FROM users WHERE password = '" . md5($password) . "' AND username = '" . $username . "' LIMIT 1"); // If there are no matches then the username and password do not match if($sql === false) { return false; } else { while($u = mysql_fetch_array($sql)) { // Check if user wants account to be saved in cookie if($remember == true) { // Generate new auth key for each log in (so old auth key can not be used multiple times in case // of cookie hijacking) $cookie_auth= rand_string(10) . $username; $auth_key = session_encrypt($cookie_auth); $auth_query = mysql_query("UPDATE users SET auth_key = '" . $auth_key . "' WHERE username = '" . $username . "'"); setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/", "mycorrectwebsite.com", false, true); } // Assign variables to session session_regenerate_id(true); $session_id = $u[id]; $session_username = $username; $session_level = $u[user_level]; $_SESSION['user_id'] = $session_id; $_SESSION['user_level'] = $session_level; $_SESSION['user_name'] = $session_username; $_SESSION['user_lastactive'] = time(); return true; } } } function initiate() { $logged_in = false; if(isset($_SESSION['user_name'])) { $logged_in = true; } // Check that cookie is set if(isset($_COOKIE['auth_key'])) { $auth_key = $_COOKIE['auth_key']; if($logged_in === false) { // Select user from database where auth key matches (auth keys are unique) $auth_key_query = mysql_query("SELECT username, password FROM users WHERE auth_key = '" . $auth_key . "' LIMIT 1"); if($auth_key_query === false) { // If auth key does not belong to a user delete the cookie setcookie("auth_key", "", time() - 3600); } else { while($u = mysql_fetch_array($auth_key_query)) { // Go ahead and log in login($u['username'], $u['password'], true); } } } else { setcookie("auth_key", "", time() - 3600); } } } And then in the header I start every page with: <?php session_start(); include("connect.php"); include("functions.php"); include("actions.php"); initiate(); ?> This is my first post here. G'day everyone. I'm having trouble with getting a session recognized from one page to another. I did a search and used the advice but I'm still having trouble. I have a page called checklogin.php that processes the information submitted for a member to login, and redirect it to login_success.php if the login was successful. The problem I have is when I test the session in the second page it tells me there is no session. Here's my code (I omitted the db connection code): Code: [Select] <?php // username and password sent from form $myusername=$_POST['user']; $mypassword=$_POST['pass']; ?> <? // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername']=$myusername; $_SESSION['mypassword']=$mypassword; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> after I am redirected to login_success.php: Code: [Select] <?php session_start(); $_SESSION['myusername']; if (isset($_SESSION['myusername'])) { $loggedin = TRUE; return $loggedin; echo "logged in."; } else echo "not logged in"; ?> It echoes "not logged in". I've struggled with this for days and I don't know what's wrong. Thanks in advance. Hi Guys, I am developer and relatively new to php although I have written a few scripts. I have a site which runs on linux/unix platform. I am facing a weird problem: - I have a php script (e.g. site.com/test/test.php) which takes a input from url, and creates a session and opens a wordpress php in another folder (e.g. site.com/wp/index.php) - I wrote a small php code in that wp/index.php which checks if session exists or not. if yes, then no problem, if not then die and show a message. Now the problem is when I run the script, it opens the wp/index.php and the page opens. Good. But when I click on any link in that page e.g about or so, then I get message which I wrote that session not found and so on... I don't know why this is happening. So if you guys can help me with this it would be great. Alternatively, I thought if I protect the wp folder (using protect folder thru cpanel) and write a php script outside which call the php inside the wp folder with a hardcoded uname & pw, then i can run the php inside without anyone knowing what the actual uname or pw is. This way if a user directly tries to access it , he wont be able to do so as uname & password box will appear. But I dunno how to call a php inside protected folder. I tried to redirect but the uname & pw box appeared. I would be grateful if anyone can help me. Thanks a lot, Cheers, GR I'm writing a shopping cart type of application for booking something. The cart will holds items as arrays in the session. The problem i'm i'm having is i can store 5 items in my cart and then once i try to store any more, it just won't. I'm not getting any php errors. I'm using the codeigniter framework, so it may be a codeigniter session storage problem. Hopefully you guys can look at it and can see if you spot any bad logic that i'm overlooking. Code: [Select] <?php //generates random unique 32 character string $booking_hash = random_string('unique'); //set items foreach night foreach($room['date_rate'] as $date => $rate) { //produces random sha1 16 char length string $sha1 = random_string('sha1', 16); $session['items'][$sha1] = array( 'code' => $room['code'], 'id' => $room_id, 'title' => $room['title'], 'date' => date("n/j/Y",strtotime($date)), 'price' => $rate, 'tax_one' => money_format('%i',$room['tax_one'] * $rate), 'tax_two' => money_format('%i',$room['tax_two'] * $rate), 'sales_tax' => 0, 'guests' => $num_guests, 'booking' => $booking_hash, 'deposit' => $deposit, ); } $existing_items = $this->session->userdata('items'); if(!empty($existing_items)) { $session['items'] = $existing_items + $session['items']; } $this->session->set_userdata($session); ?> I just read some codeigniter session documentation. It says the cookie it's using can hold 4KB of data. I have no idea how much text 4KB can hold... |