• I am a beginner to WP and I have few questions on the same.

    Is there a way to execute PHP scripts in WP without logging into the portal. I have created a portal page and written (only)PHP code in it using insert PHP plugin. I am trying to authenticate the user who logs in to my Android App by calling this script in my app. But every time I run this script/portal page directly in the browser, the page is redirected to log-in page. Is there a way to execute run the page with PHP without logging into the portal?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    Sure, much of the theme scripts are run by random visitors to your site without the need to login. It depends on what this script is doing. If it’s calling WP functions that require certain user capabilities, the login page will be presented.

    You can run your script by either directly linking to the actual PHP page, calling it from a particular template, or by having jQuery make an AJAX request to trigger the script.

    Thread Starter dashrathng

    (@dashrathng)

    Thanks for the reply.

    All I am trying to do is to have a PHP script that authenticates user by accessing the database. This PHP script will be called in the android app.

    To be more clear, I have no idea how to run any page by by-passing the log-in page. For example, I have a created a sample portal page and if I try to run it, the page is redirected to the log-in page. Please let me know if there is a way to run the page without logging in.

    My apologies if this is a very basic question, I am a newbie to WP.

    Moderator bcworkz

    (@bcworkz)

    No problem, coding related to authentication is by necessity a tricky issue. Whether you can run a particular script without logging in would depend on what that script is doing.

    If you can post a copy of your PHP page, perhaps I can give you a better idea about what’s happening. If it’s more than a dozen lines, please use pastebin.com and just link to it here.

    Thread Starter dashrathng

    (@dashrathng)

    Here is the PHP script I want to run in WP:

    Thanks for your help.

    Moderator bcworkz

    (@bcworkz)

    Well, there’s nothing related to WordPress on there that I can see. That destroys my theory, the problem lies elsewhere. Thanks for posting the code though, it eliminates a lot of possible issues.

    Are you sure you’re getting a WordPress login page and not a mySQL login page? How is this page being called? A form submit I imagine. Is this page given as the action target in the <form> tag?

    The other possibility is something about the Insert PHP plugin. The login may be a requirement for this plugin. I know nothing of this plugin nor why you even need it, so if your issue is related to this, I regret I cannot help you.

    Your script raises some broader questions in my mind, which is unrelated to login pages. You may ignore this portion if you wish, it is not really my business, but I would like to be sure you are using an optimal approach for your project. Is this user table related at all to WordPress users? For that matter, is the database with the user table at all related to the WordPress database? The reason I ask is there are advantages to keeping custom data in tables added to the WordPress database if you are using WordPress at all. Also, if your users are to be WordPress users, a more elaborate process is required.

    Thread Starter dashrathng

    (@dashrathng)

    Thanks for your reply.

    I think there is a bit of confusion here. As I stated in my question, I have not called the PHP script anywhere because I don’t know where to call it.

    If you could answer me the following question I think it will be probably easy for me to figure out the rest:

    How can I run ANY page in WP without logging in? I have created a sample portal page with only HTML content in it. Is there a way to run it by see the page without logging in, by typing in the URL of that page?

    Apologies for any confusion!

    Moderator bcworkz

    (@bcworkz)

    Yes there is confusion, I thought I answered that, apparently not very well. But even more confusing is why you are getting a WP login page, you are not calling anything related to WP from what I can see. I have to think you are getting a mySQL database login page because you are trying to access the database directly. The page you posted sends an empty password. This could result in such a login page if a password is required, assuming you didn’t just delete the password before you posted to a public site.

    Anyway, to hopefully more clearly answer your question, which I understand to be that you have a static HTML page and you want to run the script that you posted.

    This script is setup to receive a POST request with form data. Thus your HTML page must have a form with field names matching the keys for the $_POST array used in the PHP script. The <form> tag must have an action attribute equal to the URL of your PHP file and an method attribute set to “POST”. This will execute your script, though you may get a mySQL login page if you do not supply a password in your script.

    Thread Starter dashrathng

    (@dashrathng)

    “Anyway, to hopefully more clearly answer your question, which I understand to be that you have a static HTML page and you want to run the script that you posted.”

    That’s exactly what I am trying to do!

    I do have all the field names matching the keys and I have everything else ready as you mentioned. But my question still remains unanswered.

    For now, let us forget that there is a PHP script. How can I run a HTML page without logging in to the portal? How do I create such a HTML page.

    As stated earlier this is my question – ” How can I run ANY page in WP without logging in? I have created a sample portal page with only HTML content in it. Is there a way to run it and see the page without logging in, by typing in the URL of that page?”.

    Thank you for your patience.

    Moderator bcworkz

    (@bcworkz)

    Thank you for YOUR patience. I’m sorry I keep missing the mark with the information you need.

    Yes, you should just enter the URL for the page in your browser’s address bar and the page would normally be displayed without any login required. For instance, your WP install has a readme.html file in the WP root installation folder, this should open without any login.

    If you are getting a login page with this still, you may have additional security setup on your server and you may be seeing the server’s password prompt. This would be unusual behavior for the public_html (or similar) folder of your server.

    Thread Starter dashrathng

    (@dashrathng)

    Thank you very much.

    I will try running that in a public folder.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘PHP with WP’ is closed to new replies.