Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6042591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:48:27+00:00 2026-05-23T06:48:27+00:00

I face some problem on my script that I use PHP and jquery to

  • 0

I face some problem on my script that I use PHP and jquery to create login system.

First I have PHP page contain form for login. when user click submit I use jquery to send data to server

$.post('server_login.php', {username:username.val(), password:password.val()}, function(data){
    alert(data);
}); 

in server_login.php I have function to doing login user.

if($_POST['username']=='username' && $_POST['password']=='1234'){
    $expire = time() + 60*60*24*30; //1 month expired.
    setcookie("user_id", $_POST['username'], $expire);
    echo true;
}

and jquery alert “1” on my login page.

the problem is when i refresh my website and retieve cookie, it not show me.

print_r($_COOKIE);

anything wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:48:27+00:00Added an answer on May 23, 2026 at 6:48 am

    If the script you are calling is located in another folder on the server (or via url rewrite it appears as if it is under another path), make sure to set the path parameter of the cookie.

    By default, setcookie() sets the cookie only for the current path.

    If your page is www.domain.com and you make ajax call to www.domain.com/auth/login.php the cookie will be set to /auth and will not be available outside /auth.

    So try changing to this:

    setcookie("user_id", $_POST['username'], $expire, '/');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Last day my head judge me because he face with some problem that he
As the question says, what are some common/major issues that C++ programmers face when
I have tried to use ASP.NET MVC for a while, then I face a
I have a program ( grabface ) that takes a picture of the face
I design new IntSet Class that use ArrayList. first, i extends Intset by ArrayList
I face a problem when I try to get value from primary table in
Why is this archaic format still used in the face of easier-to-use technologies? Does
First of all I alwyas use one #ID. just asking this question to know
I have some user generated content I'm trying to render on my site. The
I have written a simple brainfuck interpreter in MATLAB script language. It is fed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.