Hello there dear experts, I need to pass a post session to anohter page.

I have a php script to detect mobile devices , so basically when I detect a mobile device I switch from index.html to mobile.html via header('Location'). So my problem is most of the time index.html is called with post data ,and I need to switch this data over to mobile.html ,because after all two files serve the same purpose.

I can but won't build hidden input fields and echo them out with a javascript auto posting data to mobile.html
I need something neater ,something that would behave like this:
load('mobile.html' , $_POST);

Open in new window

maybe rewrite headers or something!
Any ideas !?
LVL 10
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Since HTML pages without any javascript or PHP can not receive POST info, I'm not sure what you're even doing.  In any case, no redirect method will carry POST info with it.  It just doesn't work that way.
To answer dave's comment one can configure their web server to treat all including .html as .... Script files, adds unnecessary overhead.

Your remedy is to process the data received into a backend DB set a cookie and redirect.

Handling the data as soon as it comes in will resolve the reverse if someone access the mobile URL from a non-mobile device.

Where I your mobile detection mechanism? Within the php code or on the client side?
Not sure why you re not redirecting the user upon the initial request for the page versus waiting for the post form submission?
You oukd use server side Agent based detection to direct users, but you must be careful as one might prefer the full site versus the mobile one. So other onside rations handling has to be taken into account to allow a mobile user to access the full site.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aboo_sAuthor Commented:
I do use php to redirect users and I don't want any mobile user to access the full site, that actually is the whole point.
Now when you say use DB and a cookie ,well that is a possibility though I'm not sure if I am using a cookie then why use a DB ,or more than that why not use session variables that would make more sense.

The thing is that if I use any of the methods above then I will have to re-write most of my code in mobile.html which I was trying to avoid. So to that since I would be better off going to my first suggestion ,the one I said I wouldn't do.
(echo a redirect page on the go) That will less coding to do.

I think there must away for php to emulate a post sent to a page!
In javascript it's very easy to redirect to a page passing a post to it. can't it also be done by pure php ?
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

aboo_sAuthor Commented:
You know what ,I think I got it!
I will save $_POST variable int session and then at the top of my mobile.html file re-assign it to $_POST once again .

That should do it!!
Dave BaldwinFixer of ProblemsCommented:
Saving $_POST to $_SESSION is a good idea.  Javascript can pass $_GET data in a query string to another page but it can only send $_POST to the server.  Servers do not automatically send $_POST data back with any request.  That can only happen if the request is for a PHP (or ASP or ASP.NET) page that receives it and sends it back.  It still will not be as $_POST data.
Not sure what submits data to the index.html, but if you would check whether the person loading index.html should be loading mobile.html on access, you would be able to redirect the user to the mobile.html before they fill out and submit any forms/data.

Alternatively, whatever form is being submitted have it alter the destination on the same criteria would resolve your issue as well.
aboo_sAuthor Commented:
Arnold thank you for sharing your thoughts.
I actually had that in mind , as for what would trigger index.html , well it's a bit of a network of files, it could be called by any number of files and given data to process.

I was aiming to change only index HTML rather than the whole network of files.

And I did get it to work!

Thank you All
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.